Skip to content

Instantly share code, notes, and snippets.

@tomaszperek
Last active October 21, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaszperek/994cced1161d826d24a1 to your computer and use it in GitHub Desktop.
Save tomaszperek/994cced1161d826d24a1 to your computer and use it in GitHub Desktop.
Implementation of ScalacApplicativeBuilder
case class ScalacApplicativeBuilder[M[_], In <: HList, Out <: HList](values: In)(implicit m: Monad[M]) {
def asTuple[T](implicit ev: IsHListOfM[M, In, Out], m: Monad[M], tupler: Tupler.Aux[Out, T]): M[T] = m.map(hsequence(values))(_.tupled)
def apply[F, FOut](f: F)(implicit fnEv: FnToProduct.Aux[F, Out => FOut], ev: IsHListOfM[M, In, Out]): M[FOut] =
m.map(hsequence(values))(fnEv(f))
def :@:[X, T1](newOne: M[X]) = ScalacApplicativeBuilder[M, M[X] :: In, X :: Out](newOne :: values)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment