···56 replaceStrings seq stringLength sub substring tail;
57 inherit (trivial) id const concat or and boolToString mergeAttrs
58 flip mapNullable inNixShell min max importJSON warn info
59- nixpkgsVersion mod functionArgs setFunctionArgs isFunction;
06061 inherit (fixedPoints) fix fix' extends composeExtensions
62 makeExtensible makeExtensibleWithCustomName;
···71 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
72 concatMap flatten remove findSingle findFirst any all count
73 optional optionals toList range partition zipListsWith zipLists
74- reverseList listDfs toposort sort take drop sublist last init
75- crossLists unique intersectLists subtractLists
76 mutuallyExclusive;
77 inherit (strings) concatStrings concatMapStrings concatImapStrings
78 intersperse concatStringsSep concatMapStringsSep
···56 replaceStrings seq stringLength sub substring tail;
57 inherit (trivial) id const concat or and boolToString mergeAttrs
58 flip mapNullable inNixShell min max importJSON warn info
59+ nixpkgsVersion mod compare splitByAndCompare
60+ functionArgs setFunctionArgs isFunction;
6162 inherit (fixedPoints) fix fix' extends composeExtensions
63 makeExtensible makeExtensibleWithCustomName;
···72 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
73 concatMap flatten remove findSingle findFirst any all count
74 optional optionals toList range partition zipListsWith zipLists
75+ reverseList listDfs toposort sort compareLists take drop sublist
76+ last init crossLists unique intersectLists subtractLists
77 mutuallyExclusive;
78 inherit (strings) concatStrings concatMapStrings concatImapStrings
79 intersperse concatStringsSep concatMapStringsSep
+24
lib/lists.nix
···385 if len < 2 then list
386 else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
387000000000000000000000000388 /* Return the first (at most) N elements of a list.
389390 Example:
···385 if len < 2 then list
386 else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
387388+ /* Compare two lists element-by-element.
389+390+ Example:
391+ compareLists compare [] []
392+ => 0
393+ compareLists compare [] [ "a" ]
394+ => -1
395+ compareLists compare [ "a" ] []
396+ => 1
397+ compareLists compare [ "a" "b" ] [ "a" "c" ]
398+ => 1
399+ */
400+ compareLists = cmp: a: b:
401+ if a == []
402+ then if b == []
403+ then 0
404+ else -1
405+ else if b == []
406+ then 1
407+ else let rel = cmp (head a) (head b); in
408+ if rel == 0
409+ then compareLists cmp (tail a) (tail b)
410+ else rel;
411+412 /* Return the first (at most) N elements of a list.
413414 Example:
+36
lib/trivial.nix
···81 */
82 mod = base: int: base - (int * (builtins.div base int));
8300000000000000000000000000000000000084 /* Reads a JSON file. */
85 importJSON = path:
86 builtins.fromJSON (builtins.readFile path);
···81 */
82 mod = base: int: base - (int * (builtins.div base int));
8384+ /* C-style comparisons
85+86+ a < b, compare a b => -1
87+ a == b, compare a b => 0
88+ a > b, compare a b => 1
89+ */
90+ compare = a: b:
91+ if a < b
92+ then -1
93+ else if a > b
94+ then 1
95+ else 0;
96+97+ /* Split type into two subtypes by predicate `p`, take all elements
98+ of the first subtype to be less than all the elements of the
99+ second subtype, compare elements of a single subtype with `yes`
100+ and `no` respectively.
101+102+ Example:
103+104+ let cmp = splitByAndCompare (hasPrefix "foo") compare compare; in
105+106+ cmp "a" "z" => -1
107+ cmp "fooa" "fooz" => -1
108+109+ cmp "f" "a" => 1
110+ cmp "fooa" "a" => -1
111+ # while
112+ compare "fooa" "a" => 1
113+114+ */
115+ splitByAndCompare = p: yes: no: a: b:
116+ if p a
117+ then if p b then yes a b else -1
118+ else if p b then 1 else no a b;
119+120 /* Reads a JSON file. */
121 importJSON = path:
122 builtins.fromJSON (builtins.readFile path);