Created
September 16, 2014 21:16
-
-
Save mariogarcia/8e4bbc992d7739bd5135 to your computer and use it in GitHub Desktop.
Ideas on how to implement some list comprehensions
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
import static groovyfp.categories.Fn.* | |
import groovyfp.categories.* | |
/* | |
a = do | |
x <- (1..3) | |
y <- ('a','b') | |
return (x,y) | |
a = mdo { | |
x << (1..3) | |
y << ('a'..'b') | |
mreturn { [x, y] } | |
} | |
*/ | |
def expr = { x, y -> [x + y] } | |
def result = | |
list(1,2,3).bind { x -> | |
list('a','b').bind { y -> | |
list([expr(x,y)]) | |
} | |
} | |
result.typedRef.value | |
/* | |
m = mlet(x:10,y:20) { | |
x + y | |
} | |
*/ | |
m = just(10).bind { x -> | |
just(20).bind { y -> | |
just(x + y) | |
} | |
} | |
m.typedRef.value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment