2021-02-22 14:32:45 +01:00
|
|
|
{ depot, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
id
|
|
|
|
;
|
|
|
|
|
|
|
|
# Simple function composition,
|
|
|
|
# application is right to left.
|
|
|
|
rl = f1: f2:
|
|
|
|
(x: f1 (f2 x));
|
|
|
|
|
|
|
|
# Compose a list of functions,
|
|
|
|
# application is right to left.
|
|
|
|
rls = fs:
|
|
|
|
builtins.foldl' (fOut: f: lr f fOut) id fs;
|
|
|
|
|
|
|
|
# Simple function composition,
|
|
|
|
# application is left to right.
|
|
|
|
lr = f1: f2:
|
|
|
|
(x: f2 (f1 x));
|
|
|
|
|
|
|
|
# Compose a list of functions,
|
|
|
|
# application is left to right
|
2021-03-04 22:15:18 +01:00
|
|
|
lrs = x: fs:
|
2021-02-22 14:32:45 +01:00
|
|
|
builtins.foldl' (v: f: f v) x fs;
|
|
|
|
|
2021-04-12 19:30:41 +02:00
|
|
|
# Warning: cursed function
|
|
|
|
#
|
|
|
|
# Check if a function has an attribute
|
|
|
|
# set pattern with an ellipsis as its argument.
|
|
|
|
#
|
|
|
|
# s/o to puck for discovering that you could use
|
|
|
|
# builtins.toXML to introspect functions more than
|
|
|
|
# you should be able to in Nix.
|
|
|
|
hasEllipsis = f:
|
|
|
|
builtins.isFunction f &&
|
|
|
|
builtins.match ".*<attrspat ellipsis=\"1\">.*"
|
|
|
|
(builtins.toXML f) != null;
|
|
|
|
|
2021-02-22 14:32:45 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
inherit (lib)
|
|
|
|
fix
|
|
|
|
flip
|
|
|
|
const
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit
|
|
|
|
id
|
|
|
|
rl
|
|
|
|
rls
|
|
|
|
lr
|
|
|
|
lrs
|
2021-04-12 19:30:41 +02:00
|
|
|
hasEllipsis
|
2021-02-22 14:32:45 +01:00
|
|
|
;
|
|
|
|
}
|