mirror of
https://github.com/antirez/aocla
synced 2025-01-13 20:01:40 +01:00
18 lines
409 B
Text
18 lines
409 B
Text
|
// This is an implementation of map. There is already one inside
|
||
|
// Aocla, but this will redefine it.
|
||
|
|
||
|
[(l f) // list and function to apply
|
||
|
$l len (e) // Get list len in "e"
|
||
|
0 (j) // j is our current index
|
||
|
[] // We will populate this empty list
|
||
|
[$j $e <] [
|
||
|
$l $j get@
|
||
|
$f eval
|
||
|
swap ->
|
||
|
$j 1 + (j)
|
||
|
] while
|
||
|
] 'map def
|
||
|
|
||
|
[1 2 3] [dup *] map
|
||
|
print
|