(that: number): (self: number) => Option.Option<number>
(self: number, that: number): Option.Option<number>Divides numbers safely, returning Option.none() if the divisor is 0.
When to use
Use to divide numbers while representing division by zero as Option.none.
Example (Dividing numbers safely)
import { Number } from "effect"
Number.divide(6, 3) // Option.some(2)
Number.divide(6, 0) // Option.none()export const const divide: {
(that: number): (
self: number
) => Option.Option<number>
(
self: number,
that: number
): Option.Option<number>
}
Divides numbers safely, returning Option.none() if the divisor is 0.
When to use
Use to divide numbers while representing division by zero as Option.none.
Example (Dividing numbers safely)
import { Number } from "effect"
Number.divide(6, 3) // Option.some(2)
Number.divide(6, 0) // Option.none()
divide: {
(that: numberthat: number): (self: numberself: number) => import OptionOption.type Option<A> = Option.None<A> | Option.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<number>
(self: numberself: number, that: numberthat: number): import OptionOption.type Option<A> = Option.None<A> | Option.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<number>
} = import dualdual(
2,
(self: numberself: number, that: numberthat: number): import OptionOption.type Option<A> = Option.None<A> | Option.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<number> => that: numberthat === 0 ? import OptionOption.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() : import OptionOption.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(self: numberself / that: numberthat)
)