From f93ca99fab906b6d2b83dc3b4c9410da7c29bdde Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Mar 2015 13:01:05 +0100 Subject: initial commit --- lib/default.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/default.nix (limited to 'lib/default.nix') diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 00000000..c1663a7b --- /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}"); +} -- cgit v1.2.3