Skip to content

Instantly share code, notes, and snippets.

@aryairani
Last active August 29, 2015 14:01
Show Gist options
  • Save aryairani/95b18658426c7cc09390 to your computer and use it in GitHub Desktop.
Save aryairani/95b18658426c7cc09390 to your computer and use it in GitHub Desktop.
object Foo {
def given[A,B,C,S](aa: S => Stream[A],
bb: S => Stream[B],
cc: S => Stream[C]) = new {
def thereExists(f: (A,B,C)=>Boolean)(s: S): Boolean = {
val cross = for {
a <- aa(s)
b <- bb(s)
c <- cc(s)
} yield f(a,b,c)
cross.exists(identity)
}
}
import scalaz.syntax.applicative._
import scalaz.std.stream._
import scalaz.syntax.foldable._
import scalaz.Tags.Disjunction
def given[A,B,C,D,S](aa: S => Stream[A],
bb: S => Stream[B],
cc: S => Stream[C],
dd: S => Stream[D]) = new {
def thereExists(f: (A,B,C,D)=>Boolean)(s: S): Boolean =
^^^(aa(s),bb(s),cc(s),dd(s))(f).foldMap(Disjunction)// lift f to Stream
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment