-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add READMEs for All, Any and Arrow types (#148)
* add All, Any and Arrow readmes * remove value from `Arrow` * address review feedback
- Loading branch information
Showing
5 changed files
with
731 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# All | ||
```haskell | ||
All Boolean | ||
``` | ||
`All` is a `Monoid` that will combine two values of any type using logical | ||
conjunction (AND) on their coerced `Boolean` values, mapping truth-y values to | ||
`true` and false-y values to `false`. | ||
|
||
```js | ||
const All = require('crocks/All') | ||
const mconcat = require('crocks/helpers/mconcat') | ||
|
||
const trueNum = All(13) | ||
const falseNum = All(0) | ||
const trueString = All('So true') | ||
|
||
trueNum.concat(falseNum) | ||
//=> All false | ||
|
||
trueNum.concat(trueString) | ||
//=> All true | ||
|
||
const allGood = | ||
mconcat(All) | ||
|
||
allGood([ 1, 5, 89 ]) | ||
//=> All true | ||
|
||
allGood([ 'nice', '00', null ]) | ||
//=> All false | ||
``` | ||
|
||
## Implements | ||
`Semigroup`, `Monoid` | ||
|
||
## Constructor Methods | ||
|
||
### empty | ||
```haskell | ||
All.empty :: () -> All | ||
``` | ||
|
||
`empty` provides the identity for the `Monoid` in that when the value it | ||
provides is `concat`ed to any other value, it will return the other value. In | ||
the case of `All` the result of `empty` is `true`. `empty` is available on both | ||
the Constructor and the Instance for convenience. | ||
|
||
```js | ||
All.empty() //=> All true | ||
|
||
All(true).concat(All.empty()) //=> All true | ||
All(false).concat(All.empty()) //=> All false | ||
``` | ||
|
||
|
||
### type | ||
```haskell | ||
All.type :: () -> String | ||
``` | ||
|
||
`type` provides a string representation of the type name for a given type in | ||
`crocks`. While it is used mostly internally for law validation, it can be | ||
useful to the end user for debugging and building out custom types based on the | ||
standard `crocks` types. While type comparisons can easily be done manually by | ||
calling `type` on a given type, using the `isSameType` function hides much of | ||
the boilerplate. `type` is available on both the Constructor and the Instance | ||
for convenience. | ||
|
||
```js | ||
const Maybe = require('crocks/Maybe') | ||
const isSameType = require('crocks/predicates/isSameType') | ||
|
||
All.type() //=> "All" | ||
|
||
isSameType(All, All(3)) //=> true | ||
isSameType(All, All) //=> true | ||
isSameType(All, Maybe.Just('3')) //=> false | ||
isSameType(All(false), Maybe) //=> false | ||
``` | ||
|
||
## Instance Methods | ||
|
||
### concat | ||
```haskell | ||
All ~> All -> All | ||
``` | ||
|
||
`concat` is used to combine (2) `Semigroup`s of the same type under an operation | ||
specified by the `Semigroup`. In the case of `All`, it will combine the two | ||
using logical AND (conjunction). | ||
|
||
```js | ||
All(true).concat(All(true)) //=> All true | ||
All(true).concat(All(false)) //=> All false | ||
All(false).concat(All(true)) //=> All false | ||
All(false).concat(All(false)) //=> All false | ||
``` | ||
|
||
### valueOf | ||
```haskell | ||
All ~> () -> Boolean | ||
``` | ||
|
||
`valueOf` is used on all `crocks` `Monoid`s as a means of extraction. While the | ||
extraction is available, types that implement `valueOf` are not necessarily a | ||
`Comonad`. This function is used primarily for convenience for some of the | ||
helper functions that ship with `crocks`. Calling `valueOf` on an `All` instance | ||
will result in the underlying `Boolean` value. | ||
|
||
```js | ||
All(0).value() //=> false | ||
All('string').valueOf() //=> true | ||
|
||
//=> false | ||
All(true) | ||
.concat('') | ||
.valueOf() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Any | ||
```haskell | ||
Any Boolean | ||
``` | ||
`Any` is a `Monoid` that will combine two values of any type using logical | ||
disjunction (OR) on their coerced `Boolean` values, mapping truth-y values to | ||
`true` and false-y values to `false`. | ||
|
||
```js | ||
const Any = require('crocks/Any') | ||
const isNumber = require('crocks/predicates/isNumber') | ||
const mconcatMap = require('crocks/helpers/mconcat') | ||
|
||
const trueString = Any('string') | ||
const falseString = Any('') | ||
const object = Any({ nice: true }) | ||
|
||
trueString.concat(falseString) | ||
//=> Any false | ||
|
||
trueString.concat(object) | ||
//=> Any true | ||
|
||
const anyNumber = | ||
mconcatMap(Any, isNumber) | ||
|
||
anyNumber([ 'string', 3 ]) | ||
//=> Any true | ||
|
||
anyNumber([ true, 'string' ]) | ||
//=> Any false | ||
``` | ||
|
||
## Implements | ||
`Semigroup`, `Monoid` | ||
|
||
## Constructor Methods | ||
|
||
### empty | ||
```haskell | ||
Any.empty :: () -> Any | ||
``` | ||
|
||
`empty` provides the identity for the `Monoid` in that when the value it | ||
provides is `concat`ed to any other value, it will return the other value. In | ||
the case of `Any` the result of `empty` is `false`. `empty` is available on both | ||
the Constructor and the Instance for convenience. | ||
|
||
```js | ||
Any.empty() //=> Any false | ||
|
||
Any(true).concat(Any.empty()) //=> Any true | ||
Any(false).concat(Any.empty()) //=> Any false | ||
``` | ||
|
||
|
||
### type | ||
```haskell | ||
Any.type :: () -> String | ||
``` | ||
|
||
`type` provides a string representation of the type name for a given type in | ||
`crocks`. While it is used mostly internally for law validation, it can be | ||
useful to the end user for debugging and building out custom types based on the | ||
standard `crocks` types. While type comparisons can easily be done manually by | ||
calling `type` on a given type, using the `isSameType` function hides much of | ||
the boilerplate. `type` is available on both the Constructor and the Instance | ||
for convenience. | ||
|
||
```js | ||
const Assign = require('crocks/Assign') | ||
const isSameType = require('crocks/predicates/isSameType') | ||
|
||
Any.type() //=> "Any" | ||
|
||
isSameType(Any, Any(3)) //=> true | ||
isSameType(Any, Any) //=> true | ||
isSameType(Any(false), Assign) //=> false | ||
|
||
isSameType(Any, Assign({ food: 'always' })) | ||
//=> false | ||
``` | ||
|
||
## Instance Methods | ||
|
||
### concat | ||
```haskell | ||
Any ~> Any -> Any | ||
``` | ||
|
||
`concat` is used to combine (2) `Semigroup`s of the same type under an operation | ||
specified by the `Semigroup`. In the case of `Any`, it will combine the two | ||
using logical OR (disjunction). | ||
|
||
```js | ||
Any(true).concat(Any(true)) //=> Any true | ||
Any(true).concat(Any(false)) //=> Any true | ||
Any(false).concat(Any(true)) //=> Any true | ||
Any(false).concat(Any(false)) //=> Any false | ||
``` | ||
|
||
### valueOf | ||
```haskell | ||
Any ~> () -> Boolean | ||
``` | ||
|
||
`valueOf` is used on all `crocks` `Monoid`s as a means of extraction. While the | ||
extraction is available, types that implement `valueOf` are not necessarily a | ||
`Comonad`. This function is used primarily for convenience for some of the | ||
helper functions that ship with `crocks`. Calling `value` on an `Any` instance | ||
will result in the underlying `Boolean` value. | ||
|
||
```js | ||
Any(0).valueOf() //=> false | ||
Any('string').valueOf() //=> true | ||
|
||
//=> true | ||
Any(45) | ||
.concat('') | ||
.valueOf() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.