<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>>Creates a Combiner for Option<A> with fail-fast semantics: returns None
if either operand is None.
When to use
Use when you need an Option combiner that returns None unless both
operands are Some.
Details
None+ anything →None- anything +
None→None Some(a)+Some(b)→Some(combine(a, b))
Example (Fail-fast combining)
import { Number, Option } from "effect"
const combiner = Option.makeCombinerFailFast(Number.ReducerSum)
console.log(combiner.combine(Option.some(1), Option.some(2)))
// Output: { _id: 'Option', _tag: 'Some', value: 3 }
console.log(combiner.combine(Option.some(1), Option.none()))
// Output: { _id: 'Option', _tag: 'None' }export function function makeCombinerFailFast<A>(
combiner: Combiner.Combiner<A>
): Combiner.Combiner<Option<A>>
Creates a Combiner for Option<A> with fail-fast semantics: returns None
if either operand is None.
When to use
Use when you need an Option combiner that returns None unless both
operands are Some.
Details
None + anything → None
- anything +
None → None
Some(a) + Some(b) → Some(combine(a, b))
Example (Fail-fast combining)
import { Number, Option } from "effect"
const combiner = Option.makeCombinerFailFast(Number.ReducerSum)
console.log(combiner.combine(Option.some(1), Option.some(2)))
// Output: { _id: 'Option', _tag: 'Some', value: 3 }
console.log(combiner.combine(Option.some(1), Option.none()))
// Output: { _id: 'Option', _tag: 'None' }
makeCombinerFailFast<function (type parameter) A in makeCombinerFailFast<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>>A>(combiner: Combiner.Combiner<A>(parameter) combiner: {
combine: (self: A, that: A) => A;
}
combiner: import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<function (type parameter) A in makeCombinerFailFast<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>>A>): import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in makeCombinerFailFast<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>>A>> {
return import CombinerCombiner.make((self: Option<A>self, that: Option<A>that) => {
if (const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(self: Option<A>self) || const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(that: Option<A>that)) return const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
return const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(combiner: Combiner.Combiner<A>(parameter) combiner: {
combine: (self: A, that: A) => A;
}
combiner.combine(self: Some<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.value, that: Some<A>(parameter) that: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
that.value))
})
}