随笔分类 -  Compose

摘要:Functions returning functions returning functions can begin to look a bit unwieldy. The arrow function has helped the syntax a lot, but maybe using a 阅读全文
posted @ 2020-10-24 15:35 Zhentiw 阅读(148) 评论(0) 推荐(0)
摘要:Remeber: each broadcast return a cancel function let createTimeout = (time) => (listener) => { let id = setTimeout(listener, time) return () => { clea 阅读全文
posted @ 2020-10-24 15:29 Zhentiw 阅读(164) 评论(0) 推荐(0)
摘要:import { compose } from "ramda"; let input = document.getElementById("input"); let inputBroadcaster = (listener) => { input.addEventListener("input", 阅读全文
posted @ 2020-09-30 18:32 Zhentiw 阅读(175) 评论(0) 推荐(0)
摘要:import { compose } from "ramda"; let input = document.getElementById("input"); let inputBroadcaster = (listener) => { input.addEventListener("input", 阅读全文
posted @ 2020-09-30 18:12 Zhentiw 阅读(135) 评论(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 阅读(148) 评论(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 阅读(226) 评论(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 阅读(174) 评论(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 阅读(181) 评论(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 阅读(149) 评论(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 阅读(161) 评论(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 阅读(186) 评论(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 阅读(158) 评论(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 阅读(243) 评论(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 阅读(228) 评论(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 阅读(355) 评论(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 阅读(136) 评论(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 阅读(198) 评论(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 阅读(221) 评论(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 阅读(174) 评论(0) 推荐(0)