GithubHelp home page GithubHelp logo

meow-mtl's People

Contributors

gvolpe avatar implmnt avatar kubukoz avatar kwark avatar mrobakowski avatar oleg-py avatar terjokhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meow-mtl's Issues

Make CatsEffectMtlInstances public.

There are cases when I'd like to be able to manually instantiate RefMonadState, would you consider lifting the private on the CatsEffectMtlInstances object ?

Summon methods for optics?

given type HasNetworkConfig[R] = MkLensToType[R, NetworkConfig]

HasNetworkConfig[AppConfig] could summon an instance from the implicit scope.

ApplicativeLocal for Monix TaskLocal

TaskLocal is pretty cool and should allow us to get an instance of ApplicativeLocal, which abstracts over ReaderT.

To be done:

  • Wait for Monix 3.0.0-RC2 release
  • Create a separate module for the project
  • Implement :)

Possible support for fs2?

Hello!

Would it be possible to somehow support fs2 with deriving prisms?

I have setup my project to handle custom business errors, and it works great if I for example do Sync[F].raiseError(CustomException("test")

But does not work when doing Stream.raiseError(CustomException("test")).

The stack trace says something of the lines of CustomException: null.

Derivations for lenses with multiple fields of the same type

I was wondering what'd happen if I asked meow to generate instances/lenses for a type with same-type fields:

case class Foo(s: String, y: String)

import com.olegpy.meow.optics.MkLensToType

implicitly[MkLensToType[Foo, String]]

Current behavior: the generated lens directs to the s field.
Expected behavior: compilation error. The target type is ambiguous and could match either of the class's fields (let alone if any of them was nested), and the current behavior isn't really what a user would expect.

Do you think meow-mtl should make it harder to derive such lenses? If someone really wants to target a field that can't be uniquely determined by its type, maybe force them to pass a symbol with the field's name, or provide the lens themselves?

Trouble deriving MonadState

package sandbox

import cats._
import cats.data._
import cats.instances.list._
import cats.instances.try_._
import cats.instances.vector._
import cats.mtl._
import cats.mtl.instances.state._
import cats.syntax.functor._
import com.olegpy.meow.hierarchy._
import com.olegpy.meow.optics.MkLensToType
import shapeless.Lens

import scala.language.higherKinds
import scala.util.Try

object Sandbox extends App {
  trait World
  trait Effect
  case class Application(id: Int, name: String)
  case class Patch(field: String, value: Any)

  implicit def writerLens[T, L]: MkLensToType[Writer[L, T], T] =
    new MkLensToType(new Lens[Writer[L, T], T] {
      override def get(s: Writer[L, T]): T = s.value
      override def set(s: Writer[L, T])(a: T): Writer[L, T] = s.map(_ => a)
    })

  type Rnt[T] = RWST[Try, World, List[Effect], Writer[Vector[Patch], Application], T]

  def mod[F[_]: Functor : MonadState[?[_], Application]](f: Endo[Application]): F[Unit] = {
    MonadState[F, Application].modify(f)
  }

  deriveMonadState[Rnt, Writer[Vector[Patch], Application], Application]
}

Compiles with:

[error]  both method ambiguousIfPresent in object Refute of type [T](implicit ev: T)shapeless.Refute[T]
[error]  and method refute in object Refute of type [T](implicit dummy: DummyImplicit)shapeless.Refute[T]
[error]  match expected type com.olegpy.meow.internal.IsAbstract[sandbox.Sandbox.Rnt]
[error]   deriveMonadState[Rnt, Writer[Vector[Patch], Application], Application]

AFAIK compiler will always provide ClassTag[] for an arbitrary type, Refute will always be ambiguous in this case. Any thoughts?

Ambiguous implicits in some cases

Recently, I encountered this behavior:

//given
case class AppConfig(foo: FooConfig)
case class FooConfig(value: Int)

//when
implicit val readAppConfig: ApplicativeAsk[F, AppConfig] = new DefaultApplicativeAsk[F, AppConfig] {
  override val applicative: Applicative[F] = F
  override val ask: F[AppConfig] = config.pure[F]
}

//comment this line and the last line doesn't compile
implicitly[ApplicativeAsk[F, AppConfig]]

import com.olegpy.meow.hierarchy._
ApplicativeAsk[F, FooConfig]

The error I'd get if not for the implicitly[ line:

diverging implicit expansion for type cats.mtl.ApplicativeAsk[F,FooConfig]
[error] starting with method deriveApplicativeAsk in trait Priority2
[error] ApplicativeAsk[F, FooConfig]

I don't have any cats-mtl imports (apart from the type names ApplicativeAsk/DefaultApplicativeAsk). It appears like the compile isn't able to use the correct derivation method unless there's a hint from the user (being the implicitly[] call.

I'm using Scala 2.12.7 and meow-mtl 0.2.0. Do you think it's a compiler bug or something related to meow itself?

Consider facility to view State as Reader

It can be convenient to allow a MonadState[F, S] to serve as an ApplicativeAsk[F, S]. We can think of the former constraint as the ability to read and update system state, and the latter as simply the ability to read it. If all we need is to read the state, the least privilege principle suggests that a ApplicativeAsk[F, S] constraint is preferable.

Traditionally, Reader monad is associated with reading outside configuration. However, IME it also works well to read the domain model of a stateful application (or some part thereof, eg by the lensing techniques already available in this library).

An example of value can be found in the meow-mtl readme use case

This is a proposal to consider an opt-in extra derivation that provides a ApplicativeAsk[F, S] should a MonadState[F, S] instance be available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.