move less function to common + add list:unzip
This commit is contained in:
parent
0e6d8dcb0d
commit
f3879811c5
|
@ -25,3 +25,7 @@ fn cexec {|cond v1 v2|
|
|||
put $r
|
||||
}
|
||||
}
|
||||
|
||||
fn less {|cmp|
|
||||
put {|e1 e2| < ($cmp $e1 $e2 0)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue