标签:isa obj AMM isarray self logic flip val const
// implies :: ((a -> Boolean), (a -> Boolean)) -> a -> Boolean const implies = (p, q) => ifElse( p, compose( Boolean, q ), constant(true) ); // hasLEngth :: a -> Boolean const hasLength = compose( Boolean, length ); // isLarge :: a -> Boolean const isLarge = propSatisfies(flip(gt, 3), "length"); const arrayWithLength = implies(isArray, hasLength); const isLargeString = implies(isString, isLarge); /** * isValidStringOrArray is week can check array has length * or string is large, only for those two types * other types, such as number, objet, it return false */ const isValidStringOrArray = allPass([ or(isString, isArray), arrayWithLength, isLargeString ]); log(isLargeString(undefined)); // true log(arrayWithLength(undefined)); // true log(isValidStringOrArray(undefined)); // false log(isValidStringOrArray({})); // false log(isValidStringOrArray([1, 2])); // true log(isValidStringOrArray("fwe")); // false log(isValidStringOrArray("fwef")); // true
Crocks.js has the implementation, no need to do it yourself.
https://evilsoft.github.io/crocks/docs/functions/logic-functions.html#implies
[Functional Programming] propSatisfies with implies
标签:isa obj AMM isarray self logic flip val const
原文地址:https://www.cnblogs.com/Answer1215/p/10884176.html