Created
December 18, 2017 17:48
-
-
Save menduz/2dfb1ec8e9a5e8b33ff585edb93cbcdc to your computer and use it in GitHub Desktop.
blogpost-act-1
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
fun generator(start: Number = 0): Array<Number> = [start ~ generator(start + 1)] | |
--- | |
// This script will pick 100 numbers from | |
// the generator, that is also being filtered | |
(generator(1000) filter isEven($))[0 to 99] |
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
%dw 2.0 | |
fun myInfix(lhs: String, rhs: String): String = "$lhs $rhs" | |
--- | |
"Hello" myInfix "world!" |
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
[1, 2, 3] map (val, ix) -> { value: val, index: ix } | |
// Is the same as | |
map([1, 2, 3], (val, ix) -> { value: val, index: ix }) |
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
// for clarity, we removed the index argument of the mapping function | |
fun map<I,O>(list: Array<I>, fn: (elem: I) -> O): Array<O> = | |
list match { | |
// When we receive an empty list, we return an empty list. | |
// The execution finishes there. | |
case [] -> [] | |
// When we receive at least one element in the list, | |
// we take off the head and let a lazy tail in the stack | |
// Then we construct an array with the transformed head element and a lazy tail | |
// Since the construction and deconstruction of tails are lazy operations, | |
// this whole process behaves as a stream. | |
case [head ~ tail] -> [fn(head) ~ map(tail, fn)] | |
} |
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
%dw 2.0 | |
fun myInfix(lhs: String, rhs: String): String = "$lhs $rhs" | |
fun myInfix(lhs: Number, rhs: Number): Number = lhs + rhs | |
--- | |
[ | |
"Hello" myInfix "world!", | |
1 myInfix 2 | |
] |
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
1 to 100 map { valueX: $ } filter isEven($.valueX) groupBy floor($.valueX / 4) | |
// 1 to 100 | |
// map { valueX: $ } | |
// filter isEven($.valueX) | |
// groupBy floor($.valueX / 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment