Hyperlinkv0.8.0-beta.28

Array

Array.liftPredicateconsteffect/Array.ts:3956
<A, B extends A>(refinement: Predicate.Refinement<A, B>): (
  a: A
) => Array<B>
<A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>

Lifts a predicate into an array: returns [value] if the predicate holds, [] otherwise.

Example (Wrapping values conditionally)

import { Array } from "effect"

const isEven = (n: number) => n % 2 === 0
const to = Array.liftPredicate(isEven)
console.log(to(1)) // []
console.log(to(2)) // [2]
liftingliftOption
Source effect/Array.ts:39564 lines
export const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.
  <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>
  <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>
} = <A>(predicate: Predicate.Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []