elvish_config/lib/moi/util/common.elv
2021-08-24 20:45:25 +02:00

43 lines
680 B
Plaintext

edit:add-var ++~ [n]{ + $n 1 }
edit:add-var --~ [n]{ + $n 1 }
edit:add-var sign~ [n]{
if (> $n 0) {
put 1
} elif (< $n 0) {
put -1
} else {
put 0
}
}
edit:add-var neg~ [n]{ * $n -1 }
edit:add-var abs~ [n]{
if (< $n 0) {
neg $n
} else {
put $n
}
}
edit:add-var sum~ [@numbers]{
local:s = 0
each [e]{ s = (+ $s e) } (to-list $numbers)
}
fn -minmax [t @numbers]{
local:l = (to-list $@numbers)
if (== (count $l) 0) {
return
}
local:m = $l[0]
each [n]{
if ($t $n $m) {
m = $n
}
} $l[1..]
put $m
}
edit:add-var min~ [@numbers]{ -minmax $'<~' $@numbers }
edit:add-var max~ [@numbers]{ -minmax $'>~' $@numbers }