[Functional Programming] propSatisfies with implies
Posted answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Functional Programming] propSatisfies with implies相关的知识,希望对你有一定的参考价值。
// 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的主要内容,如果未能解决你的问题,请参考以下文章
[Functional Programming ADT] Debug a Functional JavaScript composeK Flow