[Functional Programming] Examples: When and Unless
/**
* When
*/ const _branch = (x) => {
const result = (x && x.isPublic) ?
dissoc('private', x) : x; console.log(result);
return assoc('result', 'done', result);
} const handlePublic = when(
propEq('isPublic', true),
dissoc('private')
);
const assignDone = assoc('result', 'done');
const branch = compose(
assignDone,
handlePublic
); /**Unless */
const _isDefaultArray = (x) => {
const result = !isArray(x) ?
[] :
x; return result.map(wrap => ({wrap}))
} const isDefaultArray = compose(
map(objOf('wrap')),
unless(
isArray,
constant([])
)
) log(
isDefaultArray([10,11,12,13])
)
[Functional Programming] Examples: When and Unless的更多相关文章
- BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2
In this blog post I will talk about the changes coming in Angular 2 that will improve its support fo ...
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
- Functional Programming without Lambda - Part 2 Lifting, Functor, Monad
Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...
- 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 ...
- 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 ...
- Functional programming
In computer science, functional programming is a programming paradigm, a style of building the struc ...
- Java 中的函数式编程(Functional Programming):Lambda 初识
Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...
- Functional programming idiom
A functional programming function is like a mathematical function, which produces an output that typ ...
- 关于函数式编程(Functional Programming)
初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...
随机推荐
- 腾讯云服务器的CPU ---发现大厂都很那啥
今天给同事看了下 腾讯云上面的ora从了数据库的启动问题 简单看了下 硬件配置如下: System: Host: VM_0_8_centos Kernel: -.el6.x86_64 x86_64 b ...
- 2019年5月份最热门的JavaScript开源项目
五一假期后工作的第一天,不知道你们调整好状态没有呢? 1-libpku https://github.com/lib-pku/libpku Star 15820 该项目是由一名北大在读大学生整 ...
- Vuex的简单认识
一. 什么是vuex? Vuex是一个专为了vue.js 应用程序开发的状态管理模式 二.为什么要用vuex? 构建一个大型单页面应用程序时,Vuex可以更好的帮我们的组件外部更好的统一管理状态 类似 ...
- 小记--------spark的宽依赖与窄依赖分析
窄依赖: Narrow Dependency : 一个RDD对它的父RDD,只有简单的一对一的依赖关系.RDD的每个partition仅仅依赖于父RDD中的一个partition,父RDD和子RDD的 ...
- selenium 鼠标,键盘操作
1.打开和关闭网页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/usr/bin/env python # -*- coding:u ...
- python 基础(十八)--shutil模块
shutil模块 shutil.copyfileobj(src,dst):只拷贝文件内容,需要open文件:目标文件不存在时创建,存在时覆盖 shutil.copyfileobj(open('old. ...
- Pytest+allure安装和框架搭建
接口自动化框架搭建 -- 公司系统自测使用,只跑核心业务流程 编辑中...... 1.安装Pytest pip install -U pytest 1.1Pycharm测试脚本运行 创建project ...
- 怎样理解 Vue 组件中 data 必须为函数 ?
组件意在 复用 , 若为 对象, 则会相互干扰. 且 Vue 不允许此事发生, 规定必须为函数, 否则报错. 原理如下 对象 // 模拟创建组件 var Component= function() { ...
- 基于SQL Server日志链查看数据库insert/update/delete操作(一)
在MSSQLServer2008下的语句 不同版本可能语句会有微小差别 SELECT [Slot ID], [Transaction ID], Operation, AllocUnitName, [C ...
- 文档.Write()和文档.Writeln()石材
文档.Write()和文档.Writeln()文档是Javascript对象,其中封装了许多有用的方法,其中Write()和Writeln()是直接从浏览器窗口输出文本信息的方法.文件.Write() ...