-
Notifications
You must be signed in to change notification settings - Fork 102
Add READMEs for All, Any and Arrow types #148
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# 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 false | ||
All(true).concat(All(false)) //=> All false | ||
All(false).concat(All(true)) //=> All false | ||
All(false).concat(All(false)) //=> All false | ||
``` | ||
|
||
### value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might as well name these to |
||
```haskell | ||
All ~> () -> Boolean | ||
``` | ||
|
||
`value` is used on all `crocks` `Monoid`s as a means of extraction. While the extraction is available, types that implement `value` 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 `All` instance will result in the underlying `Boolean` value. | ||
|
||
```js | ||
All(0).value() //=> false | ||
All('string').value() //=> true | ||
|
||
//=> false | ||
All(true) | ||
.concat('') | ||
.value() | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# 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 true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
|
||
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 | ||
|
||
//=> false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move under |
||
isSameType(Any, Assign({ food: 'always' })) | ||
``` | ||
|
||
## 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 | ||
``` | ||
|
||
### value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might as well name these to |
||
```haskell | ||
Any ~> () -> Boolean | ||
``` | ||
|
||
`value` is used on all `crocks` `Monoid`s as a means of extraction. While the extraction is available, types that implement `value` 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).value() //=> false | ||
Any('string').value() //=> true | ||
|
||
//=> true | ||
Any(45) | ||
.concat('') | ||
.value() | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should result to
All true