<A>(a: A): (self: Option<A>) => boolean
<A>(self: Option<A>, a: A): booleanChecks whether an Option contains a value equal to the given one, using default
structural equality.
When to use
Use when you need a quick membership test for an Option value using
standard equality.
Details
SomewhereEqual.equals(value, a)istrue→trueSomewhere not equal, orNone→false
Example (Checking containment)
import { Option } from "effect"
console.log(Option.some(2).pipe(Option.contains(2)))
// Output: true
console.log(Option.some(1).pipe(Option.contains(2)))
// Output: false
console.log(Option.none().pipe(Option.contains(2)))
// Output: falseexport const const contains: {
<A>(a: A): (self: Option<A>) => boolean
<A>(self: Option<A>, a: A): boolean
}
Checks whether an Option contains a value equal to the given one, using default
structural equality.
When to use
Use when you need a quick membership test for an Option value using
standard equality.
Details
Some where Equal.equals(value, a) is true → true
Some where not equal, or None → false
Example (Checking containment)
import { Option } from "effect"
console.log(Option.some(2).pipe(Option.contains(2)))
// Output: true
console.log(Option.some(1).pipe(Option.contains(2)))
// Output: false
console.log(Option.none().pipe(Option.contains(2)))
// Output: false
contains: {
<function (type parameter) A in <A>(a: A): (self: Option<A>) => booleanA>(a: Aa: function (type parameter) A in <A>(a: A): (self: Option<A>) => booleanA): (self: Option<A>self: type Option<A> = None<A> | 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<function (type parameter) A in <A>(a: A): (self: Option<A>) => booleanA>) => boolean
<function (type parameter) A in <A>(self: Option<A>, a: A): booleanA>(self: Option<A>self: type Option<A> = None<A> | 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<function (type parameter) A in <A>(self: Option<A>, a: A): booleanA>, a: Aa: function (type parameter) A in <A>(self: Option<A>, a: A): booleanA): boolean
} = const containsWith: <A>(
isEquivalent: (self: A, that: A) => boolean
) => {
(a: A): (self: Option<A>) => boolean
(self: Option<A>, a: A): boolean
}
Checks whether an Option contains a value equivalent to the given one, using a
custom Equivalence.
When to use
Use when you need to test whether an Option contains a value using a
custom equality check.
Details
Some where isEquivalent(value, a) is true → true
Some where not equivalent, or None → false
Example (Checking with custom equivalence)
import { Equivalence, Option } from "effect"
const check = Option.containsWith(Equivalence.strictEqual<number>())
console.log(Option.some(2).pipe(check(2)))
// Output: true
console.log(Option.some(1).pipe(check(2)))
// Output: false
console.log(Option.none().pipe(check(2)))
// Output: false
containsWith(import EqualEqual.asEquivalence())