-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-extra.nix
More file actions
27 lines (20 loc) · 849 Bytes
/
string-extra.nix
File metadata and controls
27 lines (20 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let lib = import <nixpkgs/lib>;
inherit (lib.lists) reverseList remove;
inherit (lib.strings) splitString stringToCharacters concatStrings;
inherit (import ./lists-extra.nix) dropWhile;
splitAndMap = (delimiter: func: xs:
map func (remove [] (builtins.split delimiter xs))
);
splitStringAndMap = (delimiter: func: xs:
map func (splitString delimiter xs)
);
trim = (xs:
let isWhitespace =
s: s == "\n" || s == "\r" || s == "\t" || s == " ";
chars = stringToCharacters xs;
trimFront = dropWhile isWhitespace;
trimBack = xs: reverseList (trimFront (reverseList xs));
in concatStrings (trimBack (trimFront chars))
);
stringToDigits = str: stringToCharacters (toString str);
in { inherit splitAndMap splitStringAndMap trim stringToDigits; }