Iterative Functions
One of the changes is a fix of the mixed metaphors in the iterative functions. It turned out that "We did not have all our ducks on the same page" [sic] as we had mixed the names of the functions from two different schools. Here are the final iterative functions:each
- no changemap
- was earlier calledcollect
reduce
- no changefilter
- was earlier calledselect
reject
- droppedslice
- no change
Here are some examples to illustrate their use:
[1,2,3,4].each |$item| { notice $item }
# Result: notice 1, notice 2, notice 3, notice 4
[1,2,3,4].filter |$item| { $item % 2 == 0 }
# Result: [2, 4]
[1,2,3,4].map |$item| { $item * 2 }
# Result [2, 4, 6, 8]
[1,2,3,4].reduce |$memo, $item| { $memo + $item }
# Result: 10
[1,2,3,4].slice(2) |$first, $second| { notice $first + $second }
# Result: notice 3, notice 7
One Syntax
The other mixed metaphor in the future parser was intentional; it had support for three different syntax styles for calling the iterative functions.- The recommended style with parameters outside the braces
- a Java-8 like style using an additional arrow
- and a Ruby like style with the parameters inside the braces.
No comments:
Post a Comment