A gallery of monoid definitions and some use cases

The ability to reply to discussions is limited to **PRO** members.
Want to join in the discussion? Click here to subscribe now.

1:12

A gallery of monoid definitions and some use cases

Watch this lesson now
`acc.concat is not a function`

, any ideas? Here's my code: http://bit.ly/2hqhXZ8

Posted on Github, but posting here for others. Data.Either has not implemented concat/traverse yet. Here's our either

```
const Right = x =>
({
chain: f => f(x),
ap: other => other.map(x),
traverse: (of, f) => f(x).map(Right),
map: f => Right(f(x)),
fold: (f, g) => g(x),
concat: o =>
o.fold(_ => Right(x),
y => Right(x.concat(y))),
inspect: () => `Right(${x})`
})
const Left = x =>
({
chain: f => Left(x),
ap: other => Left(x),
traverse: (of, f) => of(Left(x)),
map: f => Left(x),
fold: (f, g) => f(x),
concat: o =>
o.fold(_ => Left(x),
y => o),
inspect: () => `Left(${x})`
})
const fromNullable = x =>
x != null ? Right(x) : Left(null)
const tryCatch = f => {
try {
return Right(f())
} catch(e) {
return Left(e)
}
}
module.exports = { Right, Left, fromNullable, tryCatch, of: Right }
```