You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An object with an `of` function that puts _any_single value into it.
498
+
An object that is a [Functor](#functor) that can be created from _any_value. A pointed functor can be seen as a container that can wrap something of any type by [lifting](#lift) that value into it.
499
499
500
-
ES2015 adds `Array.of` making arrays a pointed functor.
500
+
Since JS arrays are functors (have a `.map` method) and have an `Array.of()` function they are pointed functors!
501
501
502
502
```js
503
503
Array.of(1) // [1]
504
+
505
+
Array.of(1).map(add(1)) // [2]
504
506
```
505
507
508
+
This `of` function is an example of a [Kleisli Arrow](#kleisi-composition) and an important requirement for satisfying the [Monad](#monad) interface.
509
+
510
+
511
+
One could say that JS Promise is a pointed functor since the `.then` method _can_ act like a `.map` and `Promise.resolve` acts like `of`. However, `.then` breaks the functor rules as `Promise.of(1).map(Promise.of)` would equal `Promise.of(Promise.of(1))` but `Promise.resolve(1).then(Promise.resolve)` returns `Promise.resolve(1)`. This makes `.then` act like [.chain](#monad) some of the time and like [.map](#functor) other times. This break the rules of both Functor and Monad!
512
+
506
513
## Lift
507
514
508
515
Lifting is when you take a value and put it into an object like a [functor](#pointed-functor). If you lift a function into an [Applicative Functor](#applicative-functor) then you can make it work on values that are also in that functor.
0 commit comments