[Functional Programming] propSatisfies with implies
with Programming functional
2023-09-14 08:59:14 时间
// 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
相关文章
- ROS2机器人编程简述新书推荐-A Concise Introduction to Robot Programming with ROS2
- ORA-02058: no prepared transaction found with ID string ORACLE 报错 故障修复 远程处理
- ORA-24151: no evaluation context is associated with rule string.string or rule set string.string ORACLE 报错 故障修复 远程处理
- ORA-39814: The SKIP_INDEX_MAINTENANCE option is not allowed with NO_INDEX_ERRORS. ORACLE 报错 故障修复 远程处理
- ORA-02327: cannot create index on expression with datatype string ORACLE 报错 故障修复 远程处理
- ORA-15083: failed to communicate with ASMB background process ORACLE 报错 故障修复 远程处理
- ORA-15497: diskgroup uses a sector size that is incompatible with volumes ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-013148; Symbol: ER_CANT_REPLICATE_ANONYMOUS_WITH_AUTO_POSITION; SQLSTATE: HY000 报错 故障修复 远程处理
- Cats(3)- freeK-Free编程更轻松,Free programming with freeK详解编程语言
- databaseSecure Your Oracle Database with TPS Technologies(tpsoracle)
- Secure Your Property with Reliable LinuxCompatible Video Monitoring Software(视频监控软件linux)
- Maximizing Efficiency with File Management in Linux C Programming(filelinuxc)
- Managing Memory Efficiently with Linux Mpool: A Comprehensive Guide(linuxmpool)