随笔分类 - Compose
摘要:import { compose } from "ramda"; let input = document.getElementById("input"); let inputBroadcaster = (listener) => { input.addEventListener("input",
阅读全文
摘要:Because Javascript has inconsistent way to cleanup the lisenters: removeEventListener(button, "click") clearnTimeout(id) We can implement a contract t
阅读全文
摘要:Let's say we have a command line application: const { Task } = require("../../libs/types"); const { save, all } = require("../../libs/db"); const { la
阅读全文
摘要:Path: Compose Functors -> Monad Transformers -> Free Monad Free monads, it provides a way to modelling functions as Data type. So composing / chaining
阅读全文
摘要:Path: Compose Functors -> Monad Transformers -> Free Monad Let's first see how much it sucks when dealing with nested Monads (without natural transfor
阅读全文
摘要:Path: Compose Functors -> Monad Transformers -> Free Monad Compose Functors: Let's say we have a Task holding a Either. And we want simply apply a .ma
阅读全文
摘要:const compose = (...fns) => (...args) => fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0]; const input = document.getElementById("nameIn
阅读全文
摘要:Thinking about Promise.all, once there is a Promise in the list fails, the whole promise fails. There would be good to have an 'Alernative' operator,
阅读全文
摘要:Let's say we have following semigroups: // Total: Sum up all the number const Total = (x) => ({ x, concat(o) { return Total(o.x + x); }, fold() { retu
阅读全文
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); c
阅读全文
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); /
阅读全文
摘要:Let's see the following code first: let button = document.getElementById("button"); button.addEventListener("click", (e) => { console.log(e) }); We ha
阅读全文
摘要:const Box = x => ({ map: f => Box(f(x)), chain: f => f(x), fold: f => f(x), toString: () => `Box(${x})` }) // Exercise: Box // Goal: Refactor each exa
阅读全文
该文被密码保护。
摘要:// Setup // const _ = R; const {formatMoney} = accounting; // Example Data const CARS = [ {name: "Ferrari FF", horsepower: 660, dollar_value: 700000,
阅读全文
摘要:// Definition const Endo = run => ({ run, concat: other => Endo(x => other.run(run(x))) }); Endo.empty = () => Endo(x => x); // Ex1: // const classToC
阅读全文
摘要:Normally when we use 'map', we do the transform base on the output. 'contramap' can do the transform base on the input, which means, before the orgina
阅读全文
摘要:Endo: It takes a type as string and output is the same type. It's concat methods works like composion. All the transform functions on the same input.
阅读全文
摘要:const Reader = run => ({ run, map: f => Reader(x => f(run(x))), chain: f => Reader(x => f(run(x)).run(x)), concat(o) { return Reader(x => run(x).conca
阅读全文
摘要:Reader Monad Continue with previous post, here we have some helper functions: const toUpper = s => s.toUpperCase(); const exclaim = s => `${s}!`; And
阅读全文