Hyperlinkv0.8.0-beta.28

Option

Option.containsWithconsteffect/Option.ts:2230
<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 truetrue
  • Some where not equivalent, or Nonefalse

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
elementscontains
Source effect/Option.ts:22304 lines
export const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
  (a: A): (self: Option<A>) => boolean
  (self: Option<A>, a: A): boolean
} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))
Referenced by 1 symbols