Hyperlinkv0.8.0-beta.28

Option

Option.flattenconsteffect/Option.ts:1443
<A>(self: Option<Option<A>>): Option<A>

Flattens a nested Option<Option<A>> into Option<A>.

When to use

Use when you need to remove one layer of nested Option.

Details

  • Some(Some(value))Some(value)
  • Some(None)None
  • NoneNone

Example (Flattening nested Options)

import { Option } from "effect"

console.log(Option.flatten(Option.some(Option.some("value"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'value' }

console.log(Option.flatten(Option.some(Option.none())))
// Output: { _id: 'Option', _tag: 'None' }
sequencingflatMap
Source effect/Option.ts:14431 lines
export const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)
Referenced by 3 symbols