(searchString: string): (self: string) => Option.Option<number>Returns the index of the first occurrence of a substring safely, or None if not found.
Example (Finding the first substring index)
import { pipe, String } from "effect"
pipe("abbbc", String.indexOf("b")) // Option.some(1)
pipe("abbbc", String.indexOf("z")) // Option.none()export const const indexOf: (
searchString: string
) => (self: string) => Option.Option<number>
Returns the index of the first occurrence of a substring safely, or None if not found.
Example (Finding the first substring index)
import { pipe, String } from "effect"
pipe("abbbc", String.indexOf("b")) // Option.some(1)
pipe("abbbc", String.indexOf("z")) // Option.none()
indexOf = (searchString: stringsearchString: 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> =>
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.indexOf(searchString: string, position?: number): numberReturns the position of the first occurrence of a substring.
indexOf(searchString: stringsearchString)), import numbernumber.const isGreaterThanOrEqualTo: (that: number) => (self: number) => boolean (+1 overload)isGreaterThanOrEqualTo(0))