// 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的更多相关文章

  1. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  2. Functional Programming without Lambda - Part 2 Lifting, Functor, Monad

    Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...

  3. Functional Programming without Lambda - Part 1 Functional Composition

    Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...

  4. a primary example for Functional programming in javascript

    background In pursuit of a real-world application, let’s say we need an e-commerce web applicationfo ...

  5. Functional programming

    In computer science, functional programming is a programming paradigm, a style of building the struc ...

  6. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

  7. Functional programming idiom

    A functional programming function is like a mathematical function, which produces an output that typ ...

  8. 关于函数式编程(Functional Programming)

    初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...

  9. Functional Programming 资料收集

    书籍: Functional Programming for Java Developers SICP(Structure and Interpretation of Computer Program ...

随机推荐

  1. [转帖]方正数码发布基于龙芯3A3000系列整机

    方正数码发布基于龙芯3A3000系列整机 http://www.loongson.cn/news/company/730.html 方正数码也出过龙芯相关的服务器和PC笔记本等 发布时间:2019-0 ...

  2. Hadoop_常用命令(hdfs上)

    Hadoop_常用命令(hdfs上) hadoop fs所有文件系统都可以使用 hdfs dfs仅针对于hdfs文件系统 - 1 - 查看所有目录(文件夹)及文件  hdfs dfs -ls / - ...

  3. Web安全小结之后端

  4. #undef取消宏定义

    如果你想定义这个宏那就#define X 如果你不想让你已经#define X的宏在其他地方由于引入这个包含宏定义的.h文件而引起一些编译问题,那你就#undef X掉,就这么简单. 举个简单的例子: ...

  5. python基础(十二)--模块

    模块的导入方式 import os  调用时os.rename from os import rename #只导入的特定功能 调用时rename() from asynico.events impo ...

  6. C Looooops

    看了半天的同余 扩展欧几里得 练练手 C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27079   A ...

  7. 14-Perl 引用

    1.Perl 引用引用就是指针.Perl 引用是一个标量类型,可以指向变量.数组.哈希表(也叫关联数组)甚至子程序,可以应用在程序的任何地方.2.创建引用定义变量的时候,在变量名前面加个\,就得到了这 ...

  8. charles 抓包 (一)

    在web.app开发中经常需要通过抓包来定位页面.接口返回数据的问题.在mac系统中,charles是一款功能丰富的抓包软件.可以实现app的数据抓包. 工具:charles 附送charles的破解 ...

  9. Ubuntu系统开机后不能正常使用——问题解决记录

    1.开机后桌面内容没了,搜狗输入法不能使用了,终端不能打开了 问题原因:上次关机前为了解决解压文件中文乱码问题,在/etc/profile末尾加了如下两行:(但事实上如下两行根本不能解决中文乱码问题) ...

  10. 【vue】computed 和 watch

    计算属性:computed  监听多个变量且变量是在vue实例中(依赖某个变量,变量发生改变就会触发) 侦听器:   watch        监听一个变量的变化 使用场景:watch(异步场景)  ...