From b6b22c2c22bfb2d72bf3a3c94ee549424d86bc15 Mon Sep 17 00:00:00 2001 From: derped Date: Sat, 30 Nov 2024 18:34:41 +0100 Subject: [PATCH] Update fn docs and readability. --- fn.nix | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/fn.nix b/fn.nix index 2a4a59e..d16fa84 100644 --- a/fn.nix +++ b/fn.nix @@ -2,10 +2,34 @@ with builtins; with lib; rec { + /** + Shorthand for "if condition then a else b" + + # Type + ``` + ifelse :: Bool -> Any -> Any -> Any + ``` + + # Arguments + - [condition] A condition evaluating to a boolean + - [a] Result if condition evaluates to true + - [b] Result if condition evaluates to false + + # Example + ```nix + let + myData = { val = "custom"; }; + in ifelse (myData ? val) myData.val "default" + => "custom" + ``` + */ ifelse = - a: b: c: - if a then b else c; - fileContentsOr = a: b: (ifelse (pathIsRegularFile a) a b); + condition: a: b: + if condition then a else b; + + /** + Value of PWD environment variable at evaluation time + */ cwd = builtins.getEnv "PWD"; # lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)