(index: number): (self: string) => Option.Option<number>
(self: string, index: number): Option.Option<number>Returns the Unicode code point at the specified index safely, or None if the index is out of bounds.
Example (Reading code points)
import { pipe, String } from "effect"
pipe("abc", String.codePointAt(1)) // Option.some(98)
pipe("abc", String.codePointAt(10)) // Option.none()export const const codePointAt: {
(index: number): (
self: string
) => Option.Option<number>
(
self: string,
index: number
): Option.Option<number>
}
Returns the Unicode code point at the specified index safely, or None if the index is out of bounds.
Example (Reading code points)
import { pipe, String } from "effect"
pipe("abc", String.codePointAt(1)) // Option.some(98)
pipe("abc", String.codePointAt(10)) // Option.none()
codePointAt: {
(index: numberindex: number): (self: stringself: 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<number>
(self: stringself: string, index: numberindex: 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>
} = dual<(...args: Array<any>) => any, (self: string, index: number) => Option.Option<number>>(arity: 2, body: (self: string, index: number) => Option.Option<number>): ((...args: Array<any>) => any) & ((self: string, index: number) => Option.Option<number>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, (self: stringself: string, index: numberindex: 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 OptionOption.const fromUndefinedOr: <A>(
a: A
) => Option<Exclude<A, undefined>>
Converts a possibly undefined value into an Option, leaving null
as a valid Some.
When to use
Use when you want to treat only undefined as absent while preserving null
as a meaningful value.
Details
undefined → None
- Any other value (including
null) → Some
Example (Converting possibly undefined values to an Option)
import { Option } from "effect"
console.log(Option.fromUndefinedOr(undefined))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromUndefinedOr(null))
// Output: { _id: 'Option', _tag: 'Some', value: null }
console.log(Option.fromUndefinedOr(42))
// Output: { _id: 'Option', _tag: 'Some', value: 42 }
fromUndefinedOr(self: stringself.String.codePointAt(pos: number): number | undefinedReturns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
value of the UTF-16 encoded code point starting at the string element at position pos in
the String resulting from converting this object to a String.
If there is no element at that position, the result is undefined.
If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
codePointAt(index: numberindex)))