Last active
August 29, 2015 14:05
-
-
Save fthomas/2a46366125d698e46a6c to your computer and use it in GitHub Desktop.
unchunkF.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unchunkF[F[_], A](implicit F: Foldable[F]): Process1[F[A], A] = | |
id[F[A]].flatMap(fa => emitAll(F.toIndexedSeq(fa))) | |
//id[F[A]].flatMap(fa => F.foldLeft(fa, halt: Process1[F[A], A])((p, a) => p fby emit(a))) | |
/* | |
examples: | |
scala> val tree = '2'.node('1'.node('5'.leaf), '3'.leaf) | |
tree: scalaz.Tree[Char] = <tree> | |
scala> Process(tree, '6'.leaf).pipe(process1.unchunkF).toSource.runLog.run | |
res1: IndexedSeq[Char] = Vector(2, 1, 5, 3, 6) | |
scala> Process(List(1, 2, 3), List(4)).pipe(process1.unchunkF).toSource.runLog.run | |
res2: IndexedSeq[Int] = Vector(1, 2, 3, 4) | |
BTW: It would be nice to write "empty1[F[A], A]" instead of "halt: Process1[F[A], A]" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment