Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HListFunc (Composition of functor functions) #175

Merged
merged 1 commit into from Oct 28, 2012

Conversation

eed3si9n
Copy link
Contributor

This is an improvement to #161, which implemented Func.

AppFunc data type implemented @&&& method to composite two applicative functions producing another function that returns Tuple2[F, G]. @larsrh suggested I use typelevel package, and thus Func was created to handle several typeclasses generically. @&&& was refactored to use HList, but it remained to handle only two items at a time.

What this changes

As per @larsrh's suggestion, this provides composition that produces a function that returns n-item HList.

scala> import scalaz._, scalaz.std.AllInstances._, typelevel._, Func._
import scalaz._
import scalaz.std.AllInstances._
import typelevel._
import Func._

scala> AppFuncU { (x: Int) => x + 1 } :: AppFuncU { (x: Int) => List(x, 5) } :: AppFunc.HNil
res0: scalaz.typelevel.HListFunc[scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,Int]{type M[X] = Int; type A = Int}#M,scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,List[Int]]{type M[X] = List[X]; type A = Int}#M,scalaz.typelevel.TCNil]],scalaz.Applicative,Int,Int] = scalaz.typelevel.Func$$anon$4@538f7b25

scala> res0.runA(10)
res1: scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,Int]{type M[X] = Int; type A = Int}#M,scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,List[Int]]{type M[X] = List[X]; type A = Int}#M,scalaz.typelevel.TCNil]]#Product[Int] = GenericCons(11,GenericCons(List(10, 5),GenericNil()))

scala> res0 traverse List(1, 2, 3)
res2: scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,Int]{type M[X] = Int; type A = Int}#M,scalaz.typelevel.TCCons[scalaz.Unapply[scalaz.Applicative,List[Int]]{type M[X] = List[X]; type A = Int}#M,scalaz.typelevel.TCNil]]#Product[List[Int]] = GenericCons(9,GenericCons(List(List(1, 2, 3), List(1, 2, 5), List(1, 5, 3), List(1, 5, 5), List(5, 2, 3), List(5, 2, 5), List(5, 5, 3), List(5, 5, 5)),GenericNil()))

@larsrh
Copy link
Contributor

larsrh commented Oct 28, 2012

Awesome, thanks!

larsrh added a commit that referenced this pull request Oct 28, 2012
HListFunc (Composition of functor functions)
@larsrh larsrh merged commit f79c7a8 into scalaz:scalaz-seven Oct 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants