Skip to content

Commit

Permalink
Merge pull request #224 from hemanth/jethrolarson-patch-1
Browse files Browse the repository at this point in the history
Eliminate usage of ≍
  • Loading branch information
hemanth authored Aug 2, 2022
2 parents 3a654a4 + 60b1b6f commit 83e05ed
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,32 @@ Constant(1).chain(n => Constant(n + 1)) // => Constant(1)
An object that implements a `map` function that takes a function which is run on the contents of that object. A functor must adhere to two rules:

__Preserves identity__
```
object.map(x => x) ≍ object
```

```js
object.map(x => x)
```

is equivalent to just `object`.


__Composable__

```js
object.map(x => g(f(x)))
```
object.map(compose(f, g)) ≍ object.map(g).map(f)

is equivalent to

```js
object.map(f).map(g)
```

(`f`, `g` are arbitrary functions)
(`f`, `g` are arbitrary composable functions)

A common functor in JavaScript is `Array` since it abides to the two functor rules:
The reference implementation of [Option](#option) is a functor as it satisfies the rules:

```js
;[1, 2, 3].map(x => x) // = [1, 2, 3]
some(1).map(x => x) // = some(1)
```

and
Expand All @@ -479,8 +489,8 @@ and
const f = x => x + 1
const g = x => x * 2

;[1, 2, 3].map(x => f(g(x))) // = [3, 5, 7]
;[1, 2, 3].map(g).map(f) // = [3, 5, 7]
some(1).map(x => g(f(x))) // = some(3)
some(1).map(f).map(g) // = some(3)
```

## Pointed Functor
Expand Down

0 comments on commit 83e05ed

Please sign in to comment.