Predicate overview
A simple extension to the Effect Predicate module
Table of contents
Models
EffectPredicate (interface)
Effectful predicate that returns an effectful boolean
Signature
export interface EffectPredicate<in Z, out E, out R> {
(x: Z): Effect.Effect<boolean, E, R>
}
Utility types
Coverage (type alias)
Type utiliy that extracts the type covered by a refinement or predicate. Returns never when applied to a predicate and its target when applied to a refinement.
Signature
export type Coverage<R extends MTypes.AnyPredicate> = readonly [R] extends readonly [
Predicate.Refinement<infer _, infer A>
]
? A
: never
PredicatesToCoverages (type alias)
Type utiliy that takes an array/record of predicates or refinements and returns an array/record of their coverages
Signature
export type PredicatesToCoverages<T extends PredicateArray> = {
readonly [key in keyof T]: Coverage<T[key]>
}
PredicatesToSources (type alias)
Type utiliy that takes an array of predicates or refinements and returns an array/record of their sources
Signature
export type PredicatesToSources<T extends PredicateArray> = {
readonly [key in keyof T]: Source<T[key]>
}
PredicatesToTargets (type alias)
Type utiliy that takes an array/record of predicates or refinements and returns an array/record of their targets
Signature
export type PredicatesToTargets<T extends PredicateArray> = {
readonly [key in keyof T]: Target<T[key]>
}
Source (type alias)
Type utiliy that extracts the source of a predicate or refinement.
Signature
export type Source<R extends MTypes.AnyPredicate> = readonly [R] extends readonly [Predicate.Predicate<infer A>]
? A
: never
SourcesToPredicates (type alias)
Type utiliy that takes an array/record and returns an array/record of predicates
Signature
export type SourcesToPredicates<T extends MTypes.NonPrimitive> = {
readonly [key in keyof T]: Predicate.Predicate<T[key]>
}
Target (type alias)
Type utiliy that extracts the target of a predicate or refinement.
Signature
export type Target<R extends MTypes.AnyPredicate> = readonly [R] extends readonly [
Predicate.Refinement<infer _, infer A>
]
? A
: Source<R>
Utils
struct
Same as Predicate.struct but allows field completion and makes it possible to only pass a subset of the object fields even when there are some refinements.
Signature
export declare const struct: <O extends MTypes.NonPrimitive, F extends Partial<SourcesToPredicates<MTypes.Data<O>>>>(
fields: F
) => (
o: O
) => o is {
readonly [key in keyof O]: key extends keyof F
? F[key] extends MTypes.AnyPredicate
? Target<F[key]> & O[key]
: never
: O[key]
}