(b: bigint): Option.Option<number>Converts a bigint to a number safely.
When to use
Use to convert a bigint to a JavaScript number only when it is a safe
integer.
Details
If the bigint is outside the safe integer range for JavaScript (Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER), it returns Option.none().
Example (Converting bigints to numbers)
import { BigInt as BI } from "effect"
BI.toNumber(42n) // Option.some(42)
BI.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + 1n) // Option.none()
BI.toNumber(BigInt(Number.MIN_SAFE_INTEGER) - 1n) // Option.none()export const const toNumber: (
b: bigint
) => Option.Option<number>
Converts a bigint to a number safely.
When to use
Use to convert a bigint to a JavaScript number only when it is a safe
integer.
Details
If the bigint is outside the safe integer range for JavaScript (Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER), it returns Option.none().
Example (Converting bigints to numbers)
import { BigInt as BI } from "effect"
BI.toNumber(42n) // Option.some(42)
BI.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + 1n) // Option.none()
BI.toNumber(BigInt(Number.MIN_SAFE_INTEGER) - 1n) // Option.none()
toNumber = (b: bigintb: bigint): 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> => {
if (b: bigintb > const BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
Exposes the global bigint constructor for JavaScript bigint coercion.
When to use
Use to access native JavaScript bigint constructor coercion from the Effect
module namespace.
Gotchas
This follows native BigInt coercion rules. It throws for invalid strings or
non-integral numbers, and whitespace-only strings coerce to 0n.
BigInt(var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.MAX_SAFE_INTEGER: numberThe value of the largest integer n such that n and n + 1 are both exactly representable as
a Number value.
The value of Number.MAX_SAFE_INTEGER is 9007199254740991 2^53 − 1.
MAX_SAFE_INTEGER) || b: bigintb < const BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
Exposes the global bigint constructor for JavaScript bigint coercion.
When to use
Use to access native JavaScript bigint constructor coercion from the Effect
module namespace.
Gotchas
This follows native BigInt coercion rules. It throws for invalid strings or
non-integral numbers, and whitespace-only strings coerce to 0n.
BigInt(var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.MIN_SAFE_INTEGER: numberThe value of the smallest integer n such that n and n − 1 are both exactly representable as
a Number value.
The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
MIN_SAFE_INTEGER)) {
return 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()
}
return 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(var Number: NumberConstructor
;(value?: any) => number
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number(b: bigintb))
}