<B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (
self: Option<A>
) => Option<C>
<A, B, C>(
self: Option<A>,
that: Option<B>,
f: (a: A, b: B) => C
): Option<C>Combines two Options using a provided function.
When to use
Use when you need to combine two present Option values into a computed
result.
Details
- Both
Some→ appliesf(a, b)and wraps inSome - Either
None→None
Example (Combining with a function)
import { Option } from "effect"
const person = Option.zipWith(
Option.some("John"),
Option.some(25),
(name, age) => ({ name: name.toUpperCase(), age })
)
console.log(person)
// Output:
// { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }export const const zipWith: {
<B, A, C>(
that: Option<B>,
f: (a: A, b: B) => C
): (self: Option<A>) => Option<C>
<A, B, C>(
self: Option<A>,
that: Option<B>,
f: (a: A, b: B) => C
): Option<C>
}
Combines two Options using a provided function.
When to use
Use when you need to combine two present Option values into a computed
result.
Details
- Both
Some → applies f(a, b) and wraps in Some
- Either
None → None
Example (Combining with a function)
import { Option } from "effect"
const person = Option.zipWith(
Option.some("John"),
Option.some(25),
(name, age) => ({ name: name.toUpperCase(), age })
)
console.log(person)
// Output:
// { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }
zipWith: {
<function (type parameter) B in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>B, function (type parameter) A in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>A, function (type parameter) C in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>C>(that: Option<B>that: 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) B in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>A, b: Bb: function (type parameter) B in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>B) => function (type parameter) C in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>C): (self: Option<A>self: 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 <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>A>) => 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) C in <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>C>
<function (type parameter) A in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A, function (type parameter) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B, function (type parameter) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C>(self: Option<A>self: 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 <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A>, that: Option<B>that: 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) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A, b: Bb: function (type parameter) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B) => function (type parameter) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C): 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) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C>
} = dual<(...args: Array<any>) => any, <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C) => Option<C>>(arity: 3, body: <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C) => Option<C>): ((...args: Array<any>) => any) & (<A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C) => Option<C>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
3,
<function (type parameter) A in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A, function (type parameter) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B, function (type parameter) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C>(self: Option<A>self: 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 <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A>, that: Option<B>that: 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) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>A, b: Bb: function (type parameter) B in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>B) => function (type parameter) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C): 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) C in <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>C> =>
const map: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
}
map(const product: <A, B>(
self: Option<A>,
that: Option<B>
) => Option<[A, B]>
Combines two Options into a Some containing a tuple [A, B] if both
are Some.
When to use
Use when you need to require two Option values to both be Some and keep
both values as a tuple.
Details
- Both
Some → Some([a, b])
- Either
None → None
Example (Pairing two Options)
import { Option } from "effect"
console.log(Option.product(Option.some("hello"), Option.some(42)))
// Output: { _id: 'Option', _tag: 'Some', value: ['hello', 42] }
console.log(Option.product(Option.none(), Option.some(42)))
// Output: { _id: 'Option', _tag: 'None' }
product(self: Option<A>self, that: Option<B>that), ([a: Aa, b: Bb]) => f: (a: A, b: B) => Cf(a: Aa, b: Bb))
)