add getAttrOr

This commit is contained in:
Emile Clark-Boman 2026-01-15 19:18:25 +10:00
parent fec4ecd556
commit 382ae56432

View file

@ -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`.