(n: bigint): Option.Option<bigint>Computes the integer square root of a bigint safely.
When to use
Use to compute an integer square root while representing negative input as
Option.none.
Details
For non-perfect squares, returns the largest bigint whose square is less
than or equal to the input. Returns Option.none() when the input is
negative.
Example (Calculating square roots safely)
import { BigInt } from "effect"
BigInt.sqrt(4n) // Option.some(2n)
BigInt.sqrt(9n) // Option.some(3n)
BigInt.sqrt(16n) // Option.some(4n)
BigInt.sqrt(-1n) // Option.none()export const const sqrt: (
n: bigint
) => Option.Option<bigint>
Computes the integer square root of a bigint safely.
When to use
Use to compute an integer square root while representing negative input as
Option.none.
Details
For non-perfect squares, returns the largest bigint whose square is less
than or equal to the input. Returns Option.none() when the input is
negative.
Example (Calculating square roots safely)
import { BigInt } from "effect"
BigInt.sqrt(4n) // Option.some(2n)
BigInt.sqrt(9n) // Option.some(3n)
BigInt.sqrt(16n) // Option.some(4n)
BigInt.sqrt(-1n) // Option.none()
sqrt = (n: bigintn: 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<bigint> =>
const isGreaterThanOrEqualTo: (self: bigint, that: bigint) => boolean (+1 overload)isGreaterThanOrEqualTo(n: bigintn, const bigint0: bigintbigint0) ? 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(const sqrtUnsafe: (n: bigint) => bigintReturns the integer square root of a non-negative bigint.
When to use
Use when you need to compute an integer square root for a bigint that has
already been validated as non-negative, and you want negative input to throw
instead of returning Option.none.
Details
For non-perfect squares, returns the largest bigint whose square is less
than or equal to the input.
Gotchas
Throws a RangeError if the input is negative.
Example (Calculating square roots unsafely)
import { BigInt } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigInt.sqrtUnsafe(4n), 2n)
assert.deepStrictEqual(BigInt.sqrtUnsafe(9n), 3n)
assert.deepStrictEqual(BigInt.sqrtUnsafe(16n), 4n)
sqrtUnsafe(n: bigintn)) : 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()