From 382ae56432c7e5d2d4821ab99ec6fb8c31f31a8c Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Thu, 15 Jan 2026 19:18:25 +1000 Subject: [PATCH] add getAttrOr --- nib/std/attrs.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nib/std/attrs.nix b/nib/std/attrs.nix index 984c81f..52ac329 100644 --- a/nib/std/attrs.nix +++ b/nib/std/attrs.nix @@ -5,6 +5,7 @@ attrNames elemAt filter + getAttr hasAttr isAttrs length @@ -30,6 +31,11 @@ in rec { hasAttrs = list: xs: all (x: hasAttr x xs) list; + getAttrOr = name: xs: default: + if hasAttr name xs + then getAttr name xs + else default; + /** Like `genAttrs`, but allows the name of each attribute to be specified in addition to the value. The applied function should return both the new name and value as a `nameValuePair`.