(regExp: RegExp | string): (self: string) => Option.Option<number>
(self: string, regExp: RegExp | string): Option.Option<number>Returns the index of the first match for a string or regular expression safely, or
Option.none when no match is found.
Example (Searching strings)
import { String } from "effect"
String.search("ababb", "b") // Option.some(1)
String.search("ababb", /abb/) // Option.some(2)
String.search("ababb", "d") // Option.none()export const const search: {
(regExp: RegExp | string): (
self: string
) => Option.Option<number>
(
self: string,
regExp: RegExp | string
): Option.Option<number>
}
Returns the index of the first match for a string or regular expression safely, or
Option.none when no match is found.
Example (Searching strings)
import { String } from "effect"
String.search("ababb", "b") // Option.some(1)
String.search("ababb", /abb/) // Option.some(2)
String.search("ababb", "d") // Option.none()
search: {
(regExp: string | RegExpregExp: RegExp | string): (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, regExp: string | RegExpregExp: RegExp | 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>
} = dual<(...args: Array<any>) => any, (self: string, regExp: RegExp | string) => Option.Option<number>>(arity: 2, body: (self: string, regExp: RegExp | string) => Option.Option<number>): ((...args: Array<any>) => any) & ((self: string, regExp: RegExp | string) => 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, regExp: string | RegExpregExp: RegExp | 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> =>
import OptionOption.const filter: {
<A, B extends A>(
refinement: Refinement<A, B>
): (self: Option<A>) => Option<B>
<A>(predicate: Predicate<A>): <B extends A>(
self: Option<B>
) => Option<B>
<A, B extends A>(
self: Option<A>,
refinement: Refinement<A, B>
): Option<B>
<A>(
self: Option<A>,
predicate: Predicate<A>
): Option<A>
}
filter(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(self: stringself.String.search(regexp: string | RegExp): number (+1 overload)Finds the first substring match in a regular expression search.
search(regExp: string | RegExpregExp)), import numbernumber.const isGreaterThanOrEqualTo: (that: number) => (self: number) => boolean (+1 overload)isGreaterThanOrEqualTo(0))
)