45 lines
859 B
Nix
45 lines
859 B
Nix
|
{ 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}");
|
||
|
}
|