(s: string): Option.Option<BigDecimal>Parses a decimal string into a BigDecimal safely.
When to use
Use to parse external decimal text without throwing on invalid input.
Details
Returns Option.some for valid decimal or exponent notation and
Option.none when the string cannot be parsed or would produce an unsafe
scale. The empty string parses as zero.
Example (Parsing decimal strings safely)
import { BigDecimal, Option } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigDecimal.fromString("123"), Option.some(BigDecimal.make(123n, 0)))
assert.deepStrictEqual(
BigDecimal.fromString("123.456"),
Option.some(BigDecimal.make(123456n, 3))
)
assert.deepStrictEqual(BigDecimal.fromString("123.abc"), Option.none())export const const fromString: (
s: string
) => Option.Option<BigDecimal>
Parses a decimal string into a BigDecimal safely.
When to use
Use to parse external decimal text without throwing on invalid input.
Details
Returns Option.some for valid decimal or exponent notation and
Option.none when the string cannot be parsed or would produce an unsafe
scale. The empty string parses as zero.
Example (Parsing decimal strings safely)
import { BigDecimal, Option } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigDecimal.fromString("123"), Option.some(BigDecimal.make(123n, 0)))
assert.deepStrictEqual(
BigDecimal.fromString("123.456"),
Option.some(BigDecimal.make(123456n, 3))
)
assert.deepStrictEqual(BigDecimal.fromString("123.abc"), 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<BigDecimal> => {
if (s: strings === "") {
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(const zero: BigDecimalconst zero: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
zero)
}
let let base: stringbase: string
let let exp: numberexp: number
const const seperator: numberseperator = s: strings.String.search(searcher: {
[Symbol.search](string: string): number;
}): number (+1 overload)
Finds the first substring match in a regular expression search.
search(/[eE]/)
if (const seperator: numberseperator !== -1) {
const const trail: stringtrail = s: strings.String.slice(start?: number, end?: number): stringReturns a section of a string.
slice(const seperator: numberseperator + 1)
let base: stringbase = s: strings.String.slice(start?: number, end?: number): stringReturns a section of a string.
slice(0, const seperator: numberseperator)
let exp: numberexp = 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(const trail: stringtrail)
if (let base: stringbase === "" || !var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.isSafeInteger(number: unknown): booleanReturns true if the value passed is a safe integer.
isSafeInteger(let exp: numberexp) || !const FINITE_INT_REGEXP: RegExpFINITE_INT_REGEXP.RegExp.test(string: string): booleanReturns a Boolean value that indicates whether or not a pattern exists in a searched string.
test(const trail: stringtrail)) {
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()
}
} else {
let base: stringbase = s: strings
let exp: numberexp = 0
}
let let digits: stringdigits: string
let let offset: numberoffset: number
const const dot: numberdot = let base: stringbase.String.search(searcher: {
[Symbol.search](string: string): number;
}): number (+1 overload)
Finds the first substring match in a regular expression search.
search(/\./)
if (const dot: numberdot !== -1) {
const const lead: stringlead = let base: stringbase.String.slice(start?: number, end?: number): stringReturns a section of a string.
slice(0, const dot: numberdot)
const const trail: stringtrail = let base: stringbase.String.slice(start?: number, end?: number): stringReturns a section of a string.
slice(const dot: numberdot + 1)
let digits: stringdigits = `${const lead: stringlead}${const trail: stringtrail}`
let offset: numberoffset = const trail: stringtrail.String.length: numberReturns the length of a String object.
length
} else {
let digits: stringdigits = let base: stringbase
let offset: numberoffset = 0
}
if (!const FINITE_INT_REGEXP: RegExpFINITE_INT_REGEXP.RegExp.test(string: string): booleanReturns a Boolean value that indicates whether or not a pattern exists in a searched string.
test(let digits: stringdigits)) {
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()
}
const const scale: numberscale = let offset: numberoffset - let exp: numberexp
if (!var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.isSafeInteger(number: unknown): booleanReturns true if the value passed is a safe integer.
isSafeInteger(const scale: numberscale)) {
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(const make: (
value: bigint,
scale: number
) => BigDecimal
Creates a BigDecimal from a bigint value and a scale.
When to use
Use to construct a decimal directly from its unscaled integer value and
decimal scale.
Example (Creating decimals from bigint and scale)
import { BigDecimal } from "effect"
// Create 123.45 (12345 with scale 2)
const decimal = BigDecimal.make(12345n, 2)
console.log(BigDecimal.format(decimal)) // "123.45"
// Create 42 (42 with scale 0)
const integer = BigDecimal.make(42n, 0)
console.log(BigDecimal.format(integer)) // "42"
make(var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(let digits: stringdigits), const scale: numberscale))
}