Skip to content

Instantly share code, notes, and snippets.

@pnf pnf/viewducers.scala
Created Jun 26, 2017

Embed
What would you like to do?
trait ViewTransformer[-A,+B] {
def sequence(in: Iterable[A]) = transform(in.view).to(IterableFactory.toSpecific(in.iterableFactory))
def transform(v: View[A]): View[B]
def map[C](f: B => C): ViewTransformer[A,C] = new ViewTransformerImpl[A,C,B](this) {
override def transform(v: View[A]): View[C] = prev.transform(v).map(f)
}
def flatMap[C](f: B => IterableOnce[C]): ViewTransformer[A,C] = new ViewTransformerImpl[A,C,B](this) {
override def transform(v: View[A]): View[C] = prev.transform(v).flatMap(f)
}
}
object ViewTransformer {
def id[A] = new ViewTransformer[A,A] {
def transform(v: View[A]) = v
}
}
abstract class ViewTransformerImpl[-A,+B,+Interm](val prev: ViewTransformer[A,Interm]) extends ViewTransformer[A,B]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.