mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
lib: add indexOf function
This commit is contained in:
parent
49888aeb90
commit
c52e425b02
1 changed files with 23 additions and 0 deletions
|
|
@ -75,6 +75,29 @@ let
|
|||
${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/types/default.nix
|
||||
'';
|
||||
|
||||
/* get the index an item in a list
|
||||
|
||||
indexOf :: (a -> bool) -> [a] -> int -> int
|
||||
|
||||
Example:
|
||||
indexOf (x: x == 2) [ 1 2 3 ] 0
|
||||
=> 2
|
||||
|
||||
indexOf (x: x == "x") [ 1 2 3 ] 0
|
||||
=> 0
|
||||
*/
|
||||
indexOf = f: list: fallback:
|
||||
let
|
||||
iter = index: list:
|
||||
if list == [ ] then
|
||||
fallback
|
||||
else if f (head list) then
|
||||
index
|
||||
else
|
||||
iter (index + 1) (tail list);
|
||||
in
|
||||
iter 1 list;
|
||||
|
||||
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
||||
jsonType =
|
||||
let
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue