Hyperlinkv0.8.0-beta.28

Option

Option.asconsteffect/Option.ts:1193
<B>(b: B): <X>(self: Option<X>) => Option<B>
<X, B>(self: Option<X>, b: B): Option<B>

Replaces the value inside a Some with a constant, leaving None unchanged.

When to use

Use when you need to replace a present Option value while preserving whether it was Some or None.

Example (Replacing a value)

import { Option } from "effect"

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

console.log(Option.as(Option.none(), "new value"))
// Output: { _id: 'Option', _tag: 'None' }
mappingasVoidmap
Source effect/Option.ts:11934 lines
export const as: {
  <B>(b: B): <X>(self: Option<X>) => Option<B>
  <X, B>(self: Option<X>, b: B): Option<B>
} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))
Referenced by 1 symbols