mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
add usort
This commit is contained in:
parent
0937042e07
commit
a7e4524470
@ -179,6 +179,7 @@ keys | `(keys {"a" 1 "b" 2})` | `("a" "b")` | Return a list of the keys for a
|
||||
values | `(values {"a" 1 "b" 2})` | `(1 2)` | Return a list of the values for a hash-map.
|
||||
zip | `(zip ["a" "b"] [1 2])` | `{"a":1 "b":2}` | Create a hash-map using the first sequence as keys and the second as values. Uses [array_combine](https://www.php.net/manual/en/function.array-combine.php) internally.
|
||||
sort | `(sort [6 4 8 1])` | `[1 4 6 8]` | Sort the sequence using [sort](https://www.php.net/manual/en/function.sort.php).
|
||||
usort | `(usort (fn (a b) (if (< a b) 0 1)) [3 1 5 4 2])` | `[1 2 3 4 5]` | Sort the sequence using custom comparison function using [usort](https://www.php.net/manual/en/function.usort.php).
|
||||
|
||||
### Comparison functions
|
||||
|
||||
|
@ -240,5 +240,13 @@ class Collections implements ILib
|
||||
return $a::new($data);
|
||||
}
|
||||
));
|
||||
|
||||
$env->set('usort', new CoreFunc('usort', 'Sort the sequence using custom comparison function.', 2, 2,
|
||||
function (Func $f, Seq $a) {
|
||||
$data = $a->getData();
|
||||
usort($data, $f->getClosure());
|
||||
return $a::new($data);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user