Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example in IO docs #234

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.9.1 (15 Jan 2020)
- [new] add `fromPromise` and `toPromise` to `Either` -- thanks to @wookieb ( #223 )
- [fix] fix `.isInstance` method -- thanks to @wookieb ( #221 )
- [new] add `Either.fromTry` -- thanks to @rparree ( #211 )
- [new] add `Maybe.fromEmpty` -- thanks to @customcommander ( #214 )

## 0.9.0 (19 Nov 2018)

### rc.3 (18 Nov 2018)
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# monet.js

[![Build Status](https://travis-ci.org/monet/monet.js.png)](https://travis-ci.org/monet/monet.js)
[![Build Status](https://travis-ci.org/monet/monet.js.svg)](https://travis-ci.org/monet/monet.js)


For people who wish they didn't have to program in JavaScript. [documentation](https://github.com/monet/monet.js/tree/master/docs/README.md)

For people who wish they didn't have to programme in JavaScript. [documentation](https://github.com/monet/monet.js/tree/master/docs/README.md)

## Introduction

Expand All @@ -24,7 +26,7 @@ Full detailed documentation can be found [here](https://github.com/monet/monet.j
npm install monet --save

# or to install a specific version
npm install [email protected].0
npm install [email protected].1
```

### Download
Expand Down Expand Up @@ -88,7 +90,7 @@ Please see [Ken Scambler](http://twitter.com/KenScambler)'s [excellent talk](htt
Written and maintained by Chris Myers [@cwmyers](https://twitter.com/cwmyers) and Jakub Strojewski [@ulfryk](https://twitter.com/ulfryk). Follow Monet.js at [@monetjs](http://twitter.com/monetjs).

[functionalJava]: http://functionaljava.org/
[gitZip]: https://github.com/monet/monet.js/archive/v0.9.0.zip
[gitTar]: https://github.com/monet/monet.js/archive/v0.9.0.tar.gz
[gitZip]: https://github.com/monet/monet.js/archive/v0.9.1.zip
[gitTar]: https://github.com/monet/monet.js/archive/v0.9.1.tar.gz
[npm]: https://www.npmjs.com/
[scalaz]: https://github.com/scalaz/scalaz
22 changes: 22 additions & 0 deletions docs/EITHER.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ const success = val.right()
const failure = 'some error'.left()
```

### Creating an Either from an exception

```javascript
const i = 1;
Either.fromTry(() => i.toPrecision(500))
```


### Creating an Either from a Promise
```javascript
Either.fromPromise(Promise.resolve({foo: 'bar'})) // Promise of Either.Right
Either.fromPromise(Promise.reject(new Error('error'))) // Promise of Either.Left
```

## Methods

### map
Expand Down Expand Up @@ -213,6 +227,14 @@ Either[E,A].toMaybe(): Maybe[A]

Converts to a `Maybe` dropping the left side.

### toPromise

```scala
Either[E,A].toPromise(): Promise[A]
```

Converts to resolved Promise on the right side and rejected Promise on the left side.

### ...and undocumented
- equals
- join
Expand Down
2 changes: 1 addition & 1 deletion docs/IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const read = id => IO(() => $(id).text())
const write = id => value => IO(() => $(id).text(value))
```

You can call `write(id)` until you are blue in the face but all it will do is return an `IO` with a function inside.
You can call `write(id)('foo')` until you are blue in the face but all it will do is return an `IO` with a function inside.

We can now call `map` and `flatMap` to chain this two effects together. Say we wanted to read from a `div`, convert all the text to uppercase and then write back to that `div`.

Expand Down
10 changes: 9 additions & 1 deletion docs/MAYBE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maybe

The `Maybe` type is the most common way of representing *nothingness* (or the `null` type) with making the possibilities of `NullPointer` issues disappear.
The `Maybe` type is the most common way of representing *nothingness* (or the `null` type) while making the possibilities of `NullPointer` issues disappear.

`Maybe` is effectively abstract and has two concrete subtypes: `Some` (also `Just`) and `None` (also `Nothing`).

Expand Down Expand Up @@ -45,6 +45,14 @@ Maybe.fromFalsy(false)
Maybe.fromUndefined()
Maybe.fromUndefined(undefined)
// => None

Maybe.fromEmpty()
Maybe.fromEmpty(undefined)
Maybe.fromEmpty(null)
Maybe.fromEmpty('')
Maybe.fromEmpty([])
Maybe.fromEmpty({})
// => None
```

**It's important to note that monet `Maybe` implementation treats `null` and `undefined` values in special way. Any attempt to provide `null` or `undefined` to constructor (other than `fromNull` or `fromFalsy`) will cause exception (also `fromUndefined(null)` will throw). Same will happen if it's mapped to `null` or `undefined`.**
Expand Down
2 changes: 1 addition & 1 deletion docs/READER.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ One quick win would be to `curry` the `createPrettyName` function, and make `ren
```javascript
const createPrettyName = name => printer => printer.write("hello " + name)

const render = () => createPrettyName("Tom")
const render = createPrettyName("Tom") // render(printer)
```

This is better, but what if `render` wants to perform some sort of operation on the result of `createPrettyName`? It would have to apply
Expand Down
2 changes: 1 addition & 1 deletion docs/VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Fail('grr').map(val => val + 1)
Validation[E,A].failMap(fn: E => F): Validation[F,A]
```

This will apply the supplied function over the left side of the either, if one exists, otherwise it returns the `Either` untouched. For example:
This will apply the supplied function over the fail side of the validation, if one exists, otherwise it returns the `Success` untouched. For example:

```javascript
Success('lol').failMap(e => e + 1)
Expand Down
Loading