Skip to content

Optional

Optional<S, A> = object

Defined in: Core/Optional.ts:27

Optional<S, A> focuses on a value A inside a structure S that may or may not be present. Like a Lens, but get returns Option.

Compose with other Optionals via andThen, or with a Lens via andThenLens. Convert a Lens to an Optional with Lens.toOptional.

type Profile = { username: string; bio?: string };

const bioOpt = Optional.prop<Profile>()("bio");

pipe(profile, Optional.get(bioOpt));               // Some("hello") or None
pipe(profile, Optional.set(bioOpt)("hello"));      // new Profile with bio set
pipe(profile, Optional.modify(bioOpt)(s => s + "!")); // appends if present

S

A

readonly get: (s) => Option<A>

Defined in: Core/Optional.ts:28

S

Option<A>


readonly set: (a) => (s) => S

Defined in: Core/Optional.ts:29

A

(s): S

S

S