diff options
Diffstat (limited to 'lib/default.nix')
-rw-r--r-- | lib/default.nix | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 000000000..c1663a7b8 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,44 @@ +{ pkgs, ... }: + +with builtins; + +let + inherit (pkgs.lib) stringAsChars; +in + +{ + + + # "7.4.335" -> "74" + majmin = with pkgs.lib; x : concatStrings (take 2 (splitString "." x)); + + + concat = xs : + if xs == [] + then "" + else head xs + concat (tail xs) + ; + + flip = f : x : y : f y x; + + # isSuffixOf :: String -> String -> Bool + isSuffixOf = + s : xs : + let + sn = stringLength s; + xsn = stringLength xs; + in + xsn >= sn && substring (xsn - sn) sn xs == s ; + + removeSuffix = + s : xs : substring 0 (stringLength xs - stringLength s) xs; + + # setMap :: (String -> a -> b) -> Set String a -> [b] + #setMap = f: xs: map (k : f k (getAttr k xs)) (attrNames xs); + + # setToList :: Set k a -> [a] + #setToList = setMap (_: v: v); + + shell-escape = + stringAsChars (c: if c == "\n" then ''"${c}"'' else "\\${c}"); +} |