Last active
May 9, 2021 14:37
-
-
Save einarwh/1fa56357ab259e45391994bc20b85897 to your computer and use it in GitHub Desktop.
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
%%% Some: [v] | |
%%% None: [] | |
/some { % v | |
[ exch ] % [v] | |
} def | |
/none { | |
[] | |
} def | |
/map { % A {op} %%% {op} is operation to be called for each element in A | |
[ 3 1 roll % [ A {op} | |
exch % [ {op} A | |
{ % [ {op} e | |
1 index % [ {op} e {op} | |
exec % [ {op} r %%% r is result of executing {op} on e | |
exch % [ r {op} | |
} forall % [ ... {op} | |
pop % [ ... | |
] % [ r1 r2 ... ] => [ r1 r2 ... ] | |
} def | |
/flatten { % A[B] %%% A is an array containing arrays. | |
[ exch % A[B] | | |
{ % B | | |
{} forall % ... | | |
} forall % ... | | |
] % [ ... ] | |
} def | |
/flatmap { | |
map flatten | |
} def |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment