snowfall-lib/snowfall-lib/fp/default.nix
2023-08-17 00:24:05 -07:00

61 lines
1.1 KiB
Nix

{ core-inputs
, user-inputs
, snowfall-lib
, snowfall-config
}:
let
inherit (builtins) baseNameOf dirOf;
inherit (core-inputs.nixpkgs.lib) id foldr flip;
in
{
fp = rec {
## Compose two functions.
## Example Usage:
## ```nix
## compose add-two add-one
## ```
## Result:
## ```nix
## (x: add-two (add-one x))
## ```
#@ (b -> c) -> (a -> b) -> a -> c
compose = f: g: x: f (g x);
## Compose many functions.
## Example Usage:
## ```nix
## compose-all [ add-two add-one ]
## ```
## Result:
## ```nix
## (x: add-two (add-one x))
## ```
#@ [(x -> y)] -> a -> b
compose-all = foldr compose id;
## Call a function with an argument.
## Example Usage:
## ```nix
## call (x: x + 1) 0
## ```
## Result:
## ```nix
## 1
## ```
#@ (a -> b) -> a -> b
call = f: x: f x;
## Apply an argument to a function.
## Example Usage:
## ```nix
## call (x: x + 1) 0
## ```
## Result:
## ```nix
## 1
## ```
#@ a -> (a -> b) -> b
apply = flip call;
};
}