clojure/core complement

点我查看原文

(ns $clojureDoc.core.complement)
;; Takes a fn f and returns a fn that takes the same arguments as f,
;; has the same effects, if any, and returns the opposite truth value.
;; complement接受一个f函数作为参数,并返回一个和f函数具有相同参数列表的g函数(暂且这么叫吧),
;; 若f函数返回的不为空,那么g函数返回的是f函数结果的相反结果,即f函数的结果取非运算
;; 接收一个函数,返回一个非函数,再拿参数运算
;; not是拿到参数运算,并不接受函数作为参数

;; a simple not-empty? predicate 定义一个not-empty?断言
;; (complement empty?)视为整体是一个运算符,将not-empty?定义为一个运算符
(def not-empty? (complement empty?))
;; #'user/not-empty?
(not-empty? [])
;; => false
(not-empty? [1 2])
;; => true

(map (complement even?) '(1 2 3 4))
;; => (true false true false)
(map even? '(1 2 3 4))
;; => (false true false true)

;; (map (not even?) '(1 2 3 4))

(map #(not (even? %)) '(1 2 3 4))
;; => (true false true false)

QQ交流群:967328440

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangningboo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值