随笔分类 -  Compose

摘要:import { compose } from "ramda"; let input = document.getElementById("input"); let inputBroadcaster = (listener) => { input.addEventListener("input", 阅读全文
posted @ 2020-09-30 18:12 Zhentiw 阅读(130) 评论(0) 推荐(0) 编辑
摘要:Because Javascript has inconsistent way to cleanup the lisenters: removeEventListener(button, "click") clearnTimeout(id) We can implement a contract t 阅读全文
posted @ 2020-09-29 19:12 Zhentiw 阅读(142) 评论(0) 推荐(0) 编辑
摘要:Let's say we have a command line application: const { Task } = require("../../libs/types"); const { save, all } = require("../../libs/db"); const { la 阅读全文
posted @ 2020-07-07 19:35 Zhentiw 阅读(220) 评论(0) 推荐(0) 编辑
摘要:Path: Compose Functors -> Monad Transformers -> Free Monad Free monads, it provides a way to modelling functions as Data type. So composing / chaining 阅读全文
posted @ 2020-07-01 14:54 Zhentiw 阅读(171) 评论(0) 推荐(0) 编辑
摘要:Path: Compose Functors -> Monad Transformers -> Free Monad Let's first see how much it sucks when dealing with nested Monads (without natural transfor 阅读全文
posted @ 2020-06-29 17:09 Zhentiw 阅读(170) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-06-29 14:49 Zhentiw 阅读(144) 评论(0) 推荐(0) 编辑
摘要:const compose = (...fns) => (...args) => fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0]; const input = document.getElementById("nameIn 阅读全文
posted @ 2020-06-07 17:11 Zhentiw 阅读(154) 评论(0) 推荐(0) 编辑
摘要: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, 阅读全文
posted @ 2020-06-02 15:13 Zhentiw 阅读(179) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-05-28 14:42 Zhentiw 阅读(152) 评论(0) 推荐(0) 编辑
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); c 阅读全文
posted @ 2020-05-20 03:45 Zhentiw 阅读(239) 评论(0) 推荐(0) 编辑
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); / 阅读全文
posted @ 2020-05-20 03:10 Zhentiw 阅读(224) 评论(0) 推荐(0) 编辑
摘要:Let's see the following code first: let button = document.getElementById("button"); button.addEventListener("click", (e) => { console.log(e) }); We ha 阅读全文
posted @ 2020-05-13 18:16 Zhentiw 阅读(344) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-05-09 03:40 Zhentiw 阅读(131) 评论(0) 推荐(0) 编辑
该文被密码保护。
posted @ 2020-05-07 18:22 Zhentiw 阅读(0) 评论(0) 推荐(0) 编辑
摘要:// Setup // const _ = R; const {formatMoney} = accounting; // Example Data const CARS = [ {name: "Ferrari FF", horsepower: 660, dollar_value: 700000, 阅读全文
posted @ 2020-04-26 02:06 Zhentiw 阅读(188) 评论(0) 推荐(0) 编辑
摘要:// Definition const Endo = run => ({ run, concat: other => Endo(x => other.run(run(x))) }); Endo.empty = () => Endo(x => x); // Ex1: // const classToC 阅读全文
posted @ 2020-03-15 21:12 Zhentiw 阅读(211) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-03-15 21:11 Zhentiw 阅读(159) 评论(0) 推荐(0) 编辑
摘要: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. 阅读全文
posted @ 2020-03-15 18:10 Zhentiw 阅读(139) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-03-14 05:07 Zhentiw 阅读(145) 评论(0) 推荐(0) 编辑
摘要:Reader Monad Continue with previous post, here we have some helper functions: const toUpper = s => s.toUpperCase(); const exclaim = s => `${s}!`; And 阅读全文
posted @ 2020-03-13 04:10 Zhentiw 阅读(220) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示