flora-exception
Version:
An exception system for FQL.
36 lines (33 loc) • 687 B
text/typescript
import {
IsArray,
Reduce,
If,
Lambda,
Var,
And
} from "faunadb";
import { GuardedT } from "Flora/Fx";
const agg = "agg";
const el = "el";
/**
* Checks if all elements in an array are of a certain type
* @param Predicate
* @returns
*/
export const $Array = <P extends (obj : any)=>boolean>(Predicate : P)=>(obj : any) : obj is GuardedT<P>[]=>{
return If(
IsArray(obj),
Reduce(
Lambda(
[agg, el],
And(
Var(agg),
Predicate(Var(el))
)
),
true,
obj
),
false
) as unknown as boolean
}