Skip to content

Commit

Permalink
Merge branch 'master' into chore/assoc-to-setProp
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsoft committed Nov 3, 2018
2 parents adcd8cb + caf04ed commit 6868f4d
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 33 deletions.
98 changes: 75 additions & 23 deletions docs/src/pages/docs/crocks/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -1330,12 +1330,12 @@ eitherToAsync :: Either b a -> Async b a
eitherToAsync :: (a -> Either c b) -> a -> Async c b
```

Used to transform a given [`Either`][either] instance to
an `Async` instance, `eitherToAsync` will turn a [`Right`][right] instance into
a [`Resolved`](#resolved) instance wrapping the original value contained in the
original [`Right`][right]. If a [`Left`][left] is provided,
then `eitherToAsync` will return a [`Rejected`](#rejected) instance, wrapping
the original [`Left`][left] value.
Used to transform a given [`Either`][either] instance to an `Async` instance or
flatten an `Async` of `Either` into an `Async` when chained, `eitherToAsync` will
turn a [`Right`][right] instance into a [`Resolved`](#resolved) instance
wrapping the original value contained in the original [`Right`][right]. If a
[`Left`][left] is provided, then `eitherToAsync` will return a
[`Rejected`](#rejected) instance, wrapping the original [`Left`][left] value.

Like all `crocks` transformation functions, `eitherToAsync` has two possible
signatures and will behave differently when passed
Expand Down Expand Up @@ -1401,6 +1401,16 @@ Resolved('Bubble')
.chain(eitherToAsync(isValid))
.fork(log('rej'), log('res'))
//=> rej: "Bubble is not valid"

Resolved(Left('Alone'))
.chain(eitherToAsync)
.fork(log('rej'), log('res'))
//=> rej: "Alone"

Resolved(Right('Away'))
.chain(eitherToAsync)
.fork(log('rej'), log('res'))
//=> res: "Away"
```

#### firstToAsync
Expand All @@ -1412,10 +1422,10 @@ firstToAsync :: e -> First a -> Async e a
firstToAsync :: e -> (a -> First b) -> a -> Async e b
```

Used to transform a given [`First`][first] instance to
an `Async` instance, `firstToAsync` will turn a non-empty [`First`][first] instance into
a [`Resolved`](#resolved) instance wrapping the original value contained in the
original non-empty.
Used to transform a given [`First`][first] instance to an `Async` instance or
flatten an `Async` of `First` into an `Async` when chained, `firstToAsync` will
turn a non-empty [`First`][first] instance into a [`Resolved`](#resolved)
instance wrapping the original value contained in the original non-empty.

The [`First`][first] datatype is based on a [`Maybe`][maybe] and as such its left or empty value
is fixed to a `()` type. As a means to allow for convenient
Expand Down Expand Up @@ -1492,6 +1502,16 @@ Resolved([ 'cat', 'bat', 'imp' ])
.chain(findFirstValid)
.fork(log('rej'), log('res'))
//=> rej: "Nothing Found"

Resolved(First.empty())
.chain(firstToAsync('Left'))
.fork(log('rej'), log('res'))
//=> rej: "Left"

Resolved(First(42))
.chain(firstToAsync('Left'))
.fork(log('rej'), log('res'))
// => res: 42
```

#### lastToAsync
Expand All @@ -1503,10 +1523,10 @@ lastToAsync :: e -> Last a -> Async e a
lastToAsync :: e -> (a -> Last b) -> a -> Async e b
```

Used to transform a given [`Last`][last] instance to
an `Async` instance, `lastToAsync` will turn a non-empty [`Last`][last] instance into
a [`Resolved`](#resolved) instance wrapping the original value contained in the
original non-empty.
Used to transform a given [`Last`][last] instance to an `Async` instance or
flatten an `Async` of `Last` into an `Async` when chained, `lastToAsync` will
turn a non-empty [`Last`][last] instance into a [`Resolved`](#resolved)
instance wrapping the original value contained in the original non-empty.

The [`Last`][last] datatype is based on a [`Maybe`][maybe] and as such its left or empty value
is fixed to a `()` type. As a means to allow for convenient
Expand Down Expand Up @@ -1583,6 +1603,16 @@ Resolved([ 'cat', 'bat', 'imp' ])
.chain(findLastValid)
.fork(log('rej'), log('res'))
//=> rej: "Nothing Found"

Resolved(Last.empty())
.chain(lastToAsync('Left'))
.fork(log('rej'), log('res'))
//=> rej: "Left"

Resolved(Last('too know!'))
.chain(lastToAsync('Left'))
.fork(log('rej'), log('res'))
// => res: "too know!"
```

#### maybeToAsync
Expand All @@ -1594,10 +1624,10 @@ maybeToAsync :: e -> Maybe a -> Async e a
maybeToAsync :: e -> (a -> Maybe b) -> a -> Async e b
```

Used to transform a given [`Maybe`][maybe] instance to
an `Async` instance, `maybeToAsync` will turn a [`Just`][just] instance into
a [`Resolved`](#resolved) instance wrapping the original value contained in the
original [`Just`][just].
Used to transform a given [`Maybe`][maybe] instance to an `Async` instance or
flatten an `Async` of `Maybe` into an `Async` when chained, `maybeToAsync` will
turn a [`Just`][just] instance into a [`Resolved`](#resolved) instance wrapping
the original value contained in the original [`Just`][just].

A [`Nothing`][nothing] instance is fixed to a `()` type and as such can only ever contain
a value of `undefined`. As a means to allow for convenient
Expand Down Expand Up @@ -1660,6 +1690,16 @@ Resolved('')
.chain(maybeToAsync('Invalid', isValid))
.fork(log('rej'), log('res'))
//=> rej: "Invalid"

Resolved(Nothing())
.chain(maybeToAsync('Left'))
.fork(log('rej'), log('res'))
//=> rej: "Left"

Resolved(Just('the 2 of us'))
.chain(maybeToAsync('Left'))
.fork(log('rej'), log('res'))
// => res: "the 2 of us"
```

#### resultToAsync
Expand All @@ -1671,11 +1711,12 @@ resultToAsync :: Result b a -> Async b a
resultToAsync :: (a -> Result c b) -> a -> Async c b
```

Used to transform a given `Result` instance to
an `Async` instance, `resultToAsync` will turn an `Ok` instance into
a [`Resolved`](#resolved) instance wrapping the original value contained in the
original `Ok`. If an `Err` is provided, then `resultToAsync` will return
a [`Rejected`](#rejected) instance, wrapping the original `Err` value.
Used to transform a given `Result` instance to an `Async` instance or flatten an
`Async` of `Result` into an `Async` when chained, `resultToAsync` will turn an
`Ok` instance into a [`Resolved`](#resolved) instance wrapping the original
value contained in the original `Ok`. If an `Err` is provided, then
`resultToAsync` will return a [`Rejected`](#rejected) instance, wrapping the
original `Err` value.

Like all `crocks` transformation functions, `resultToAsync` has two possible
signatures and will behave differently when passed either a `Result` instance
Expand Down Expand Up @@ -1736,6 +1777,17 @@ Resolved('103')
.bimap(x => x.message, identity)
.fork(log('rej'), log('res'))
//=> rej: "Must be a Number"

Resolved(Err('Invalid entry'))
.chain(resultToAsync)
.fork(log('rej'), log('res'))
//=> rej: "Invalid entry"

Resolved(Ok('Success!'))
.chain(resultToAsync)
.fork(log('rej'), log('res'))
// => res: "Success!"

```

</article>
Expand Down
56 changes: 46 additions & 10 deletions docs/src/pages/docs/crocks/Maybe.md
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,8 @@ eitherToMaybe :: (a -> Either c b) -> a -> Maybe b
```

Used to transform a given [`Either`][either] instance to a `Maybe`
instance, `eitherToMaybe` will turn a [`Right`][right] instance into
instance or flatten a `Maybe` of `Either` into a `Maybe` when chained,
`eitherToMaybe` will turn a [`Right`][right] instance into
a [`Just`](#just) wrapping the original value contained in the [`Right`][right].
All [`Left`][left] instances will map to a [`Nothing`](#nothing), mapping the
originally contained value to a `Unit`. Values on the [`Left`][left] will be
Expand Down Expand Up @@ -1384,6 +1385,14 @@ Nothing()
Just(99)
.chain(eitherToMaybe(someNumber))
//=> Just 99

Just(Right(42))
.chain(eitherToMaybe)
// Just 42

Just(Left(24))
.chain(eitherToMaybe)
// Nothing
```

#### firstToMaybe
Expand All @@ -1396,9 +1405,10 @@ firstToMaybe :: (a -> First b) -> a -> Maybe b
```

Used to transform a given [`First`][first] instance to a `Maybe`
instance, `firstToMaybe` will turn a non-empty instance into
a [`Just`](#just) wrapping the original value contained within
the [`First`][first]. All empty instances will map to a [`Nothing`](#nothing).
instance or flatten a `Maybe` of `First` into a `Maybe` when chained,
`firstToMaybe` will turn a non-empty instance into a [`Just`](#just) wrapping
the original value contained within the [`First`][first]. All empty instances
will map to a [`Nothing`](#nothing).

Like all `crocks` transformation functions, `firstToMaybe` has two possible
signatures and will behave differently when passed either
Expand Down Expand Up @@ -1438,6 +1448,14 @@ Just([])
Just([ 'first', 'second', 'third' ])
.chain(firstToMaybe(firstValue))
//=> Just "first"

Just(First('first'))
.chain(firstToMaybe)
//=> Just "first"

Just(First.empty())
.chain(firstToMaybe)
//=> Nothing
```

#### lastToMaybe
Expand All @@ -1449,10 +1467,11 @@ lastToMaybe :: Last a -> Maybe a
lastToMaybe :: (a -> Last b) -> a -> Maybe b
```

Used to transform a given [`Last`][last] instance to a `Maybe` instance,
`lastToMaybe` will turn a non-empty instance into a [`Just`](#just) wrapping the
original value contained within the [`Last`][last]. All empty instances will map
to a [`Nothing`](#nothing).
Used to transform a given [`Last`][last] instance to a `Maybe` instance or
flatten a `Maybe` of `Last` into a `Maybe` when chained, `lastToMaybe` will
turn a non-empty instance into a [`Just`](#just) wrapping the original value
contained within the [`Last`][last]. All empty instances will map to a
[`Nothing`](#nothing).

Like all `crocks` transformation functions, `lastToMaybe` has two possible
signatures and will behave differently when passed either
Expand Down Expand Up @@ -1492,6 +1511,14 @@ Just([])
Just([ 'first', 'second', 'third' ])
.chain(lastToMaybe(lastValue))
//=> Just "third"

Just(Last('last'))
.chain(lastToMaybe)
//=> Just "last"

Just(Last.empty())
.chain(lastToMaybe)
//=> Nothing
```

#### resultToMaybe
Expand All @@ -1504,8 +1531,9 @@ resultToMaybe :: (a -> Result e b) -> a -> Maybe b
```

Used to transform a given `Result` instance to a `Maybe`
instance, `resultToMaybe` will turn an `Ok` instance into
a [`Just`](#just) wrapping the original value contained in the `Ok`.
instance or flatten a `Maybe` of `Result` into a `Maybe` when chained,
`resultToMaybe` will turn an `Ok` instance into a [`Just`](#just) wrapping the
original value contained in the `Ok`.
All `Err` instances will map to a [`Nothing`](#nothing), mapping the originally
contained value to a `Unit`. Values on the `Err` will be lost and as such this
transformation is considered lossy in that regard.
Expand Down Expand Up @@ -1551,6 +1579,14 @@ Just('so good')
Just('so good')
.chain(resultToMaybe(Ok))
//=> Just "so good"

Just(Result('in time!'))
.chain(resultToMaybe)
//=> Just "in time!"

Just(Err('to be human'))
.chain(resultToMaybe)
//=> Nothing
```
</article>

Expand Down

0 comments on commit 6868f4d

Please sign in to comment.