elvish_config/lib/moi/util/common.elv

43 lines
674 B
Plaintext
Raw Normal View History

2021-08-24 18:45:25 +00:00
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]{
2021-08-27 20:06:49 +00:00
var s = 0
2021-08-24 18:45:25 +00:00
each [e]{ s = (+ $s e) } (to-list $numbers)
}
fn -minmax [t @numbers]{
2021-08-27 20:06:49 +00:00
var l = (to-list $@numbers)
2021-08-24 18:45:25 +00:00
if (== (count $l) 0) {
return
}
2021-08-27 20:06:49 +00:00
var m = $l[0]
2021-08-24 18:45:25 +00:00
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 }