> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canton.network/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# DA.Optional

> Reference documentation for Daml module DA.Optional.

Daml module

# DA.Optional

The Optional type encapsulates an optional value. A value of type

Daml

[Updated 3.5.1](#history-updated-3-5-1)

Module
DA.Optional

Latest release
3.7.5

## Functions

### `fromSome`

`fromSome` : [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> `a`

The `fromSome` function extracts the element out of a `Some` and
throws an error if its argument is `None`.

Note that in most cases you should prefer using `fromSomeNote`
to get a better error on failures.

### `fromSomeNote`

`fromSomeNote` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> `a`

Like `fromSome` but with a custom error message.

### `catOptionals`

`catOptionals` : \[[`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a`] -> \[`a`]

The `catOptionals` function takes a list of `Optionals` and returns a
list of all the `Some` values.

### `listToOptional`

`listToOptional` : \[`a`] -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a`

The `listToOptional` function returns `None` on an empty list or
`Some` a where a is the first element of the list.

### `optionalToList`

`optionalToList` : [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> \[`a`]

The `optionalToList` function returns an empty list when given
`None` or a singleton list when not given `None`.

### `fromOptional`

`fromOptional` : `a` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> `a`

The `fromOptional` function takes a default value and a `Optional`
value. If the `Optional` is `None`, it returns the default values
otherwise, it returns the value contained in the `Optional`.

### `isSome`

`isSome` : [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

The `isSome` function returns `True` iff its argument is of the
form `Some _`.

### `isNone`

`isNone` : [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

The `isNone` function returns `True` iff its argument is
`None`.

### `mapOptional`

`mapOptional` : (`a` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `b`) -> \[`a`] -> \[`b`]

The `mapOptional` function is a version of `map` which can throw out
elements. In particular, the functional argument returns something
of type `Optional b`. If this is `None`, no element is added on to
the result list. If it is `Some b`, then `b` is included in the
result list.

### `whenSome`

`whenSome` : [`Applicative`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-applicative-9257) `m` => [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> (`a` -> `m` ()) -> `m` ()

Perform some operation on `Some`, given the field inside the
`Some`.

### `whenSome_`

`whenSome_` : [`Applicative`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-applicative-9257) `m` => [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> (`a` -> `m` `b`) -> `m` ()

Perform some operation on `Some` and discard its result,
given the field inside the `Some`.

### `whenNone`

`whenNone` : [`Applicative`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-applicative-9257) `m` => [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> `m` `a` -> `m` `a`

Perform some operation on `None`.
Otherwise returns content of `Some` pured to Applicative.

### `whenNone_`

`whenNone_` : [`Applicative`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-applicative-9257) `m` => [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a` -> `m` `b` -> `m` ()

Perform some operation on `None`. Do nothing for `Some`.
Convenient for discarding `Some` content.

### `findOptional`

`findOptional` : (`a` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `b`) -> \[`a`] -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `b`

The `findOptional` returns the value of the predicate at the first
element where it returns `Some`. `findOptional` is similar to `find` but it
allows you to return a value from the predicate. This is useful both as a more
type safe version if the predicate corresponds to a pattern match
and for performance to avoid duplicating work performed in the predicate.

## History

Updated
`3.5.1`

Module declarations or documentation updated.
