diff --git a/readme.md b/readme.md index df9be4a..1e599b2 100644 --- a/readme.md +++ b/readme.md @@ -166,6 +166,15 @@ Simplest functor in javascript is an `Array` ``` --- +## Lift + +> Lift takes a function and runs it on values in a container type. Map is a lift over a one-argument function, but the same principal can be used to combine multiple containers of the same type. + +```js +lift(n => n * 2)([2,3,4]); // [4,6,8] +lift((a, b) => a * b)([1, 2], [3]); // [3, 6] +``` + ## Referential Transparency > An expression that can be replaced with its value without changing the @@ -184,6 +193,8 @@ referential transparent. ## Equational Reasoning +> When an application is composed of expressions and devoid of side effects, truths about the system can be derived from the parts. + --- ## Lazy evaluation @@ -243,7 +254,7 @@ The identity value is empty array `[]` ## Monad -> A monad is an abstraction that provides an interface for executing a common sequence of commands on a particular kind of value, often one you want to avoid acting on directly. One of the most common monads is the "maybe" or optional value monad, which wraps a value that could be either nothing or something. By using a monad instead of the raw value, you can protect your code from exposure to null values. Likewise, a "state" monad can be used in a parser to algorithmically consume an input string using a repeatable sequence of steps that preserves the current state of the input from operation to operation. Also, since a monad is, by definition, a special kind of functor that also returns a monad, they can be chained together to describe any sequence of operations. In functional languages with lazy evaluation, monads are used where sequence of evaluation is important, such as in I/O. Due to this sequencing utility, they are sometimes referred to as "programmable semicolons." +> A monad is a container type that provides two functions, [chain](#chain) and [ap](#applicative-functor). Monads provide an interface for executing a common sequence of commands on a particular kind of value, often one you want to avoid acting on directly. One of the most common monads is the "maybe" or optional value monad, which wraps a value that could be either nothing or something. By using a monad instead of the raw value, you can protect your code from exposure to null values. Likewise, a "state" monad can be used in a parser to algorithmically consume an input string using a repeatable sequence of steps that preserves the current state of the input from operation to operation. Also, since a monad is, by definition, a special kind of functor that also returns a monad, they can be chained together to describe any sequence of operations. In functional languages with lazy evaluation, monads are used where sequence of evaluation is important, such as in I/O. Due to this sequencing utility, they are sometimes referred to as "programmable semicolons." The simplest monad is the Identity monad. It simply wraps a value. @@ -253,12 +264,28 @@ let Identity = v => ({ bind: transform => transform(v) }) --- +## Chain + +> A chain is a container type that implements a chain function. The chain function takes another function to run on the contained value and returns a value in the same container. The passed function must also return a value in the same container. This is also known as bind, or flatmap in other languages. + +```js +['cat,dog','fish,bird'].chain((a) => a.split(',')) // ['cat','dog','fish','bird'] +``` + +--- + ## Comonad --- ## Applicative Functor +> An applicative functor is a container type that can have functions put in it. A function often called `ap` is available on the type which applies a function in the container to a value in another container of the same type. + +```js +[(a)=> a + 1].ap([1]) // [2] +``` + ---