ProjectSeptemberInc / freek

Freek, a freaky simple Free to combine your DSL seamlessly
Other
197 stars 19 forks source link

OnionT should implement MonadFilter #22

Open pandaforme opened 7 years ago

pandaforme commented 7 years ago

ADT:

sealed trait UserGetter[A]
object UserGetter {
  final case class Get(userName: UserName) extends UserGetter[Either[Error, Option[User]]]
}
sealed trait UserPasswordChecker[A]
object UserPasswordChecker {
  final case class Check(clientSecret: UserPassword, hashText: BcryptHashText)
      extends UserPasswordChecker[Either[Error, Boolean]]
}

Program:

    type PRG = UserGetter :|: UserPasswordChecker :|: NilDSL
    type O = Either[Error, ?] :&: Option :&: Bulb

    for {
      u <- UserGetter.Get(UserName(username)).freeko[PRG, O]
      r <- UserPasswordChecker.Check(UserPassword(password), u.hashedPassword).freeko[PRG, O]
      if (r)
    } yield {
      Option(u)
    }

Compile Error:

value filter is not a member of freek.OnionT[cats.free.Free,[A]freek.In2[oauth2.domain.adt.UserGetter,oauth2.domain.adt.UserPasswordChecker,A],O,Boolean]

OnionT should implement [MonadFilter](https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/MonadFilter.scala) !?

I think it is very common to use guards in for comprehensions.

If FreeK offers this feature, it should be more nicer~

mandubian commented 7 years ago

Hey, have you tried to implement it? That would be interesting to see what it modifies as you'll certainly modify to filter inner monads too...