Last active
December 11, 2016 23:52
-
-
Save asarkar/2b0067be4a67d2e34358ff52b695e1b4 to your computer and use it in GitHub Desktop.
Can this be done using Applicative?
This file contains hidden or 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
val l = (1 to 20) | |
val isEven = (i: Int) => i % 2 == 0 | |
val isLtTen = (i: Int) => i < 10 | |
val isGtTen = (i: Int) => i > 10 | |
val p1 = List(isEven, isLtTen) | |
val p2 = List(isEven, isGtTen) | |
val r1 = l.find(i => p1.forall(_ (i))) | |
val r2 = l.find(i => p2.forall(_ (i))) | |
println(r1) // Some(2) | |
println(r2) // Some(12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment