diff --git a/mods/common.elv b/mods/common.elv index f5843d3..7daccbf 100644 --- a/mods/common.elv +++ b/mods/common.elv @@ -25,3 +25,7 @@ fn cexec {|cond v1 v2| put $r } } + +fn less {|cmp| + put {|e1 e2| < ($cmp $e1 $e2 0) +} diff --git a/mods/list.elv b/mods/list.elv index 3d9052a..1a71e63 100644 --- a/mods/list.elv +++ b/mods/list.elv @@ -126,6 +126,19 @@ fn first {|&from=$nil &reverse=$false cb @argv| } } +fn unzip {|cb @argv| + var a1 a2 = [] [] + loop $@argv | each {|e| + var i v = $@e + if ($cb $i $v) { + set @a1 = $@a1 $v + } else { + set @a2 = $@a2 $v + } + } + put $a1 $a2 +} + fn reduce {|acc cb @argv| each {|e| set acc = ($cb $acc $e) @@ -169,10 +182,6 @@ fn swap {|i j @argv| } } -fn less {|cb| - put {|a b| < ($cb $a $b) 0 } -} - fn sort {|cb @argv| - order &less-than=(less $cb) (-l $@argv) + order &less-than=(common:less $cb) (-l $@argv) }