• Utility function to create a specification from a predicate function

    Type Parameters

    • T

    Parameters

    • predicate: (candidate: T) => boolean

      A function that returns true if the candidate satisfies the specification

    • Optionaldescription: string

    Returns Specification<T>

    A new specification wrapping the predicate

    const isAdult = fromPredicate<Person>(p => p.age >= 18);
    const isEligible = isAdult.and(fromPredicate(p => p.hasValidId));