Skip to content

Instantly share code, notes, and snippets.

@fthomas
Last active August 29, 2015 14:05
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 fthomas/2a46366125d698e46a6c to your computer and use it in GitHub Desktop.
Save fthomas/2a46366125d698e46a6c to your computer and use it in GitHub Desktop.
unchunkF.scala
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