-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplymap.es
More file actions
51 lines (46 loc) · 857 Bytes
/
applymap.es
File metadata and controls
51 lines (46 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# part of system.es
fn apply fun args {
for (i = $args)
$fun $i
}
fn map fun lst {
local (
tmplist = ()
tmp = ()
) {
for (i = $lst) {
tmp = <={$fun $i}
tmplist = $tmplist $tmp
}
return $tmplist
}
}
# bqmap is functionally similar to map. The primary difference is that
# instead of using the <= operator it uses `. This is for situations
# where you want the program's output instead of return values. Do note
# the program's output is not flattened.
fn bqmap fun lst {
local (
tmplist = ()
tmp = ()
) {
for (i = $lst) {
tmp = `{$fun $i}
tmplist = $tmplist $tmp
}
return $tmplist
}
}
# this is bqmap, but the program's output is flattened before insertion.
fn fbqmap fun lst {
local (
tmplist = ()
tmp = ()
) {
for (i = $lst) {
tmp = `{$fun $i}
tmplist = $tmplist $^tmp
}
return $tmplist
}
}