Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

attrsets

isEmpty

Check if a value of arbitrary type is empty.

Inputs

value
The value to check for emptiness.

Type

isEmpty :: Any -> Bool

Examples

isEmpty ""
=> true
isEmpty null
=> true
isEmpty [ ]
=> true
isEmpty { }
=> true
isEmpty "foo"
=> false
isEmpty [ "foo" ]
=> false
isEmpty { foo = "bar"; }
=> false

isNotEmpty

Check if a value of arbitrary type is non-empty. Opposite of isEmpty.

Inputs

value
The value to check for non-emptiness.

Type

isNotEmpty :: Any -> Bool

Examples

isNotEmpty ""
=> false

maybe

Return the value if the condition is true, otherwise return null.

Inputs

cond
The condition to check.
value
The value to return if the condition is true.

Type

maybe :: Bool -> Any -> Any

Examples

maybe true "foo"
=> "foo"
maybe false "foo"
=> null

isEnabled

Checks if an attrset has a key with the name enable set to true.

Inputs

x
The attrset to check.

Type

isEnabled :: { enable ? Bool } -> Bool

Examples

isEnabled { enable = true; }
=> true
isEnabled { enable = false; }
=> false
isEnabled { }
=> false

getLeaves

Get all leaves of an attrset.

Inputs

attrs
The attrset to get the leaves of.

Type

getLeaves :: AttrSet -> AttrSet

Examples

getLeaves {
  foo = {
    bar = "baz";
  };
}
=> {
  "foo.bar" = "baz";
}

attrByDottedPath

Return an attribute from nested attribute sets.

Inputs

path
The path to the attribute.
default
The default value to return if the attribute does not exist.
set
The attribute set to get the attribute from.

Type

attrByPath :: String -> Any -> AttrSet -> Any

Examples

attrByPath "foo.bar" "default" { foo = { bar = "baz"; }; }
=> "baz"

getAttrFromDottedPath

Like attrByDottedPath, but without a default value. If it doesn’t find the path it will throw an error.

Inputs

path
The path to the attribute.
set
The attribute set to get the attribute from.

Type

getAttrFromDottedPath :: String -> AttrSet -> Any

Examples

getAttrFromDottedPath "foo.bar" { foo = { bar = "baz"; }; }
=> "baz"

setAttrByDottedPath

Create a new attribute set with value set at the nested attribute location specified in PATH.

Inputs

path
The path to the attribute.
value
The value to set.

Type

setAttrByDottedPath :: String -> Any -> AttrSet

Examples

setAttrByDottedPath "foo.bar" "baz"
=> { foo = { bar = "baz"; }; }