optional
lib.lists.optional
Docs pulled from | This Revision | 10 minutes ago
Return a singleton list or an empty list, depending on a boolean
value. Useful when building lists with optional elements
(e.g. ++ optional (system == "i686-linux") firefox
).
Inputs
cond
-
1. Function argument
elem
-
2. Function argument
Type
optional :: bool -> a -> [a]
Examples
lib.lists.optional
usage example
optional true "foo"
=> [ "foo" ]
optional false "foo"
=> [ ]
Noogle detected
Implementation
The following is the current implementation of this function.
optional = cond: elem: if cond then [ elem ] else [ ];