随笔分类 - Javascript
摘要:What is Arrow Functor? Arrow is a Profunctor that lifts a function of type a -> b and allows for lazy execution of the function. Arrow can be consider
阅读全文
摘要:Let's we have some prediction functions, for each prediction function has a corresponding tag: So if we have input as: Also we wish our program to the
阅读全文
摘要:What we are going to do in this post, is to build a random number generator. As you might know that Javascript provides Math.random(), but the problem
阅读全文
摘要:Implement a job scheduler which takes in a function f and an integer n, and calls f after nmilliseconds
阅读全文
摘要:The act of currying can be described as taking a multivariate function and turning it into a series of unary functions. Let's see an example: This is
阅读全文
摘要:This post is similar to previous post. The difference is in this post, we are going to see how to handle both successfuly result and error result by u
阅读全文
摘要:Let's say we are going to read some files, return the first file which pass the prediction method, this prediction method can be just check whether th
阅读全文
摘要:/**@abstract * Write your own Math.pow(a int, b int) function * */ function pow (a, b) { let result = 0; let nigate = b = 2) { result = isEven ? pow(a, b / 2) * pow(a, b / 2) : a * pow(...
阅读全文
摘要:cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and
阅读全文
摘要:You probably have functions that aren’t equipped to accept a Maybe as an argument. And in most cases, altering functions to accept a specific containe
阅读全文
摘要:We can dot-chain our way to great success with an instance of Maybe, but there are probably cases where you need to apply the same series of transform
阅读全文
摘要:We've seen how we can transduce from arrays or other iterables, but plain objects aren't iterable in Javascript. In this lesson we'll modify our trans
阅读全文
摘要:We see three varied examples of where natural transformations come in handy. Let's mark the law here for Natural Transformations: Then let's see why w
阅读全文
摘要:Natural Transformations, let's explain it by using a coding example, for example, we have a 'Either' holding a value 'a' and we want to transform a' T
阅读全文
摘要:We use the traversable instance on List to reimplement Promise.all() type functionality. For example we want to conver: Conver array of Task, into Tas
阅读全文
摘要:We annihilate the need for the ol' nested for loop using Applicatives. For example we have this kind of nested loop code: We can refactor it by using
阅读全文
摘要:Working our way backwards from solution to problem, we define an applicative functor, then use it to apply a function of multiple arguments. For examp
阅读全文
摘要:We refactor a standard node callback style workflow into a composed task-based workflow. Original Code: Using Task: Using Async:
阅读全文
摘要:Let's examine a pointfree way to write these applicative calls. Since we know map is equal to of/ap, we can write generic functions that will ap as ma
阅读全文
摘要:We examine the data structure Task, see some constructors, familiar methods, and finally how it captures side effects through laziness. We are going t
阅读全文