Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.8-beta-1
-
Fix Version/s: 1.8-beta-2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
It would be useful to support something like F#'s compose '>>' operator for Closures, e.g.:
def twice = { a -> a * 2 }
def inc = { b -> b + 1 }
def f = inc >> twice
def g = { x -> twice(inc(x)) } // longhand equivalent
assert f(10) == 22
assert g(10) == 22
def string2char = { it.chars[0] }
def p = Integer.&toHexString >> string2char >> Character.&toUpperCase
assert p(15) == 'F'
def multiply = { a, b -> a * b }
def identity = { a -> [a, a] }
def sq = identity >> multiply
assert (1..5).collect{ sq(it) } == [1, 4, 9, 16, 25]
Proposed patch attached