4 ms·
Personally I would go for something more like this: STDIN | /\w+/ | {|each match| /house/ => "foo" /car/ => "bar" "literal" => "baz
by breuleux 12y ago
Personally I would go for something more like this:
STDIN | /\w+/ | {|each match|
/house/ => "foo"
/car/ => "bar"
"literal" => "baz"
_ => "dib"
}
Where "each x" in a parameter list wraps the body in a map and uses x as the loop variable, and "match" in a parameter list instructs that this is the parameter we are doing pattern matching on in the body (no need to name it).
I think this is a more flexible solution, and more modifiers than each could be introduced. For instance, sum of squares could be:
seq(100) | {|each x| x * x} | {|reduce (x = 0, y)| x + y}