Ludwig.Optional

Module Members

equal

(Function)

Test if two Optional values are equal.

Example:

x1: equal(Optional("Foo"), None, String.equal)           # => False
x2: equal(None, None, String.equal)                      # => True
x3: equal(Optional(42), Optional(42), fun(x, y): x == y) # => True

Type Signature

 fun (Optional<a>, Optional<a>, fun (a, a) -> Bool) -> Bool
Argument: this

The first value to compare.

Type: Optional<a>

Argument: that

The value to compare to this.

Type: Optional<a>

Argument: test

The function used to test if the Optional elements are equal.

Type: fun ( a, a) -> Bool

Returns:

True if the values are equal, otherwise False.

Type: Bool

isNone

(Function)

Test if an Ludwig.Optional value is None.

Example:

x1: isNone(None)         # => True
x2: isNone(Optional(42)) # => False

Type Signature

 fun (Optional<a>) -> Bool
Argument: option

The Ludwig.Optional to test.

Type: Optional<a>

Returns:

True if option is None, False otherwise.

Type: Bool

map

(Function)

Apply a function to an Optional value.

Type Signature

 fun (fun (a) -> b, Optional<a>) -> Optional<b>
Argument: f

The function to apply.

Type: fun ( a) -> b

Argument: option

The Ludwig.Optional to operate on.

Type: Optional<a>

Returns:

None if option is None. Otherwise an Ludwig.Optional of f applied to options wrapped value.

Example:

x1: map(fun(x) x + 1, Optional(42)) # => Optional(43)
x2: map(fun(x) x + 1, None)         # => None

Type: Optional<b>

mapUnpack

(Function)

Apply a function to the value in an Ludwig.Optional and return the result or return the provided default value if the Ludwig.Optional is None.

Type Signature

 fun (b, fun (a) -> b, Optional<a>) -> b
Argument: default

The default value.

Type: b

Argument: f

The function to apply to the value in option.

Type: fun ( a) -> b

Argument: option

The Ludwig.Optional value.

Type: Optional<a>

Returns:

default if option is None, otherwise apply f to the value in option and return the result.

Example:

x1: mapUnpack(42, fun(x): x + 1, Optional(42)) # => 43
x2: mapUnpack(42, fun(x): x + 1, None)         # => 42

Type: b

optional

(Function)

DEPRECATED: Use mapUnpack instead.

Apply a function to the value in an Ludwig.Optional and return the result or return the provided default value if the Ludwig.Optional is None.

Type Signature

 fun (b, fun (a) -> b, Optional<a>) -> b
Argument: default

The default value.

Type: b

Argument: f

The function to apply to the value in option.

Type: fun ( a) -> b

Argument: option

The Ludwig.Optional value.

Type: Optional<a>

Returns:

default if option is None, otherwise apply f to the value in option and return the result.

Example:

x1: optional(42, fun(x): x + 1, Optional(42)) # => 43
x2: optional(42, fun(x): x + 1, None)         # => 42

Type: b

unpack

(Function)

Unpack a value from an Optional.

Example:

x1: unpack("foo", Optional("bar")) # => "bar"
x2: unpack("foo", None)            # => "foo

Type Signature

 fun (a, Optional<a>) -> a
Argument: default

The default value to return if option is None.

Type: a

Argument: option

The optional value to unpack.

Type: Optional<a>

Returns:

default if option is None, otherwise returns the wrapped value.

Type: a

unpackOrError

(Function)

Unpack a value from an Optional. If there is no value, this function errors with the given error message.

Example:

x1: unpackOrError(Optional(1), "printer on fire")  # => 1
x2: unpackOrError(None, "printer on fire")         # => error("printer on fire")

Type Signature

 fun (Optional<a>, String) -> a
Argument: option

The Optional value to unpack.

Type: Optional<a>

Argument: msg

The error message in case option is None.

Type: String

Returns:

The unpacked value (or never returns, in case of an error).

Type: a