<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
SomewhereisEquivalent(value, a)istrue→trueSomewhere not equivalent, orNone→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: falseexport const 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 = <function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A>(isEquivalent: (self: A, that: A) => booleanisEquivalent: (self: Aself: function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A, that: Athat: function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A) => boolean): {
(a: Aa: function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A): (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>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A>) => boolean
(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>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A>, a: Aa: function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A): boolean
} => import dualdual(2, (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>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A>, a: Aa: function (type parameter) A in <A>(isEquivalent: (self: A, that: A) => boolean): {
(a: A): (self: Option<A>) => boolean;
(self: Option<A>, a: A): boolean;
}
A): boolean => const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(self: Option<A>self) ? false : isEquivalent: (self: A, that: A) => booleanisEquivalent(self: Option<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
self.Some<A>.value: Avalue, a: Aa))