[Functional Programming] propSatisfies with implies
with Programming functional
2023-09-14 09:00:48 时间
// 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
相关文章
- Failed to find Platform SDK with path: platforms;android-30「建议收藏」
- 【Kotlin】标准库函数总结 ( apply 函数 | let 函数 | run 函数 | with 函数 | also 函数 | takeIf 函数 | takeUnless 函数 )
- ORA-00331: log version string incompatible with ORACLE version string ORACLE 报错 故障修复 远程处理
- ORA-01463: cannot modify column datatype with current constraint(s) ORACLE 报错 故障修复 远程处理
- ORA-01675: max_commit_propagation_delay inconsistent with other instances ORACLE 报错 故障修复 远程处理
- ORA-23324: error string, while creating deferror entry at “string” with error string ORACLE 报错 故障修复 远程处理
- ORA-39132: object type “string”.”string” already exists with different hashcode ORACLE 报错 故障修复 远程处理
- ORA-55443: a virtual model cannot be used with a rulebase in a SEM_MATCH query ORACLE 报错 故障修复 远程处理
- ORA-15097: cannot SHUTDOWN ASM instance with connected client (process string) ORACLE 报错 故障修复 远程处理
- ORA-15471: volume redundancy incompatible with diskgroup redundancy ORACLE 报错 故障修复 远程处理
- Pushing the Boundaries of Computing with Linux: A Revolution in Progress(pushlinux)
- Boost Your Programming Skills with Linux Development(linux开发程序)