(s: string): Option.Option<bigint>Parses a string into a bigint safely.
When to use
Use to parse a string as a bigint without throwing on invalid input.
Details
If the string is empty or contains characters that cannot be converted into a
bigint, it returns Option.none().
Example (Parsing strings as bigints)
import { BigInt } from "effect"
BigInt.fromString("42") // Option.some(42n)
BigInt.fromString(" ") // Option.none()
BigInt.fromString("a") // Option.none()export const const fromString: (
s: string
) => Option.Option<bigint>
Parses a string into a bigint safely.
When to use
Use to parse a string as a bigint without throwing on invalid input.
Details
If the string is empty or contains characters that cannot be converted into a
bigint, it returns Option.none().
Example (Parsing strings as bigints)
import { BigInt } from "effect"
BigInt.fromString("42") // Option.some(42n)
BigInt.fromString(" ") // Option.none()
BigInt.fromString("a") // Option.none()
fromString = (s: strings: string): 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> => {
try {
return s: strings.String.trim(): stringRemoves the leading and trailing white space and line terminator characters from a string.
trim() === ""
? 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(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(s: strings))
} catch {
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()
}
}