monoids is a semi-group with a neutral element. A semigroup, it does not have an element to return so it's not a safe operation, whereas with the monoids we could take as many as we possibly want, even none, and still return us back something. It's a…
We'll examine how to unnest function calls, capture assignment, and create a linear data flow with a type we call Box. This is our introduction to working with the various container-style types. At first, might not be comforable with 'Box' or 'Contai…
We refactor a function that uses try/catch to a single composed expression using Either. We then introduce the chain function to deal with nested Eithers resulting from two try/catch calls. For example we have this code using try & catch: const getPo…
We define the Either type and see how it works. Then try it out to enforce a null check and branch our code. Now, we try to make Box more useful. We want to do a force null check by define "Right" and "Left" tow boxes. What "Right…
After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nested expression. For example, we have code: const moneyToFloat = str => { const cost = str.replace(/\$/g, ''); return parseFloat(cost); } const percentT…
const { List } = require('immutable-ext'); const Right = x => ({ chain : f => f(x), ap : other => other.map(x), traverse : (of, f) => f(x).map(Right), map : f => Right(f(x)), fold : (f, g) => g(x), concat : o => o.fold(_ => Right(x…
Let's we want to combine two account accidently have the same name. , friends: ['Franklin'] } , friends: ['Gatsby'] } So, here we can use Semi-group to combine them, because the semi-group have the knowledge how to combine for each type of object. So…
An introduction to concatting items via the formal Semi-group interface. Semi-groups are simply a type with a concat method that are associative. We define three semigroup instances and see them in action.   A semigroup is a type with a concat method…
前提 已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0. 初始化数据 启动MongoDB服务,在test数据库中插入一条实例数据: db.user.install({name:"scaleworld",age:27}); 在Node.js中引入MongoDB模块 npm install mongodb 编写mongodbDemo.js var mongodb = require('mongodb'); var server…
Node.js与MongoDB的基本连接示例 前提 已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0. 初始化数据 启动MongoDB服务,在test数据库中插入一条实例数据: db.user.install({name:"scaleworld",age:27}); 在Node.js中引入MongoDB模块 npm install mongodb 编写mongodbDemo.js var mongodb = require(…