-
Notifications
You must be signed in to change notification settings - Fork 102
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
Adds Identity API to docs #38
Changes from 1 commit
95d13a7
facce30
077e492
fa420c7
b2775be
82df8f7
3020043
3736fbb
32be547
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
test | ||
*.spec.js | ||
docs | ||
|
||
.travis.yml | ||
.jshintignore | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Identity | ||
|
||
`Identity : a -> a` | ||
|
||
It's just a function which returns what you pass into it. | ||
|
||
## What a crock! | ||
|
||
It converts your `non-crock` into a `crock` | ||
|
||
```js | ||
const frozenPizza = Identity('pizza') //Identity pizza | ||
const microwave = x => 'microwave ' + x | ||
const dinner = frozenPizza.map(microwave) //Identity "microwave pizza" | ||
dinner.value() // "microwave pizza" | ||
``` | ||
|
||
| Constructor | Instance | | ||
|:---|:---| | ||
| [`of`](#of) | [`ap`](#ap), [`chain`](#chain), [`equals`](#equals), [`map`](#map), [`of`](#of), [`sequence`](#sequence), [`traverse`](#traverse), [`value`](#value) | | ||
|
||
## Constructors | ||
|
||
### of | ||
|
||
```js | ||
crocks.Identity.of([1,2,10]) | ||
crocks.Identity([1,2,10]) | ||
``` | ||
|
||
## Instances | ||
|
||
### ap | ||
|
||
`Function (a -> b) -> Function b` | ||
|
||
### chain | ||
|
||
`(a -> m b) -> m b` | ||
|
||
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. Different types of instance definitions: explicit 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. Here So as this is specifically an Identity, it could (and maybe should) be written as: Although it would probably look better as: If that makes sense? 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. But then should all defs be prefixed by the representing monad? |
||
### equals | ||
|
||
`x -> Boolean` | ||
|
||
### map | ||
|
||
`(a -> b) -> Function b` | ||
|
||
### of | ||
|
||
`a -> Function a` | ||
|
||
### sequence | ||
|
||
`Type (m a) -> m (Type a)` | ||
|
||
### traverse | ||
|
||
`a -> Function b -> Function b` | ||
|
||
### value | ||
|
||
`a -> a` |
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.
Different type of definition for constructor; here is only a definition by example
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.
of
is a very specific function that signals anApplicative
.In many cases the normal constructor function is the same thing as
of
.We still include
of
in those cases so any functions that rely on callingof
can call it.So the constructor parameters should be represented by the type siggy in most cases.
For things like
Writer
it takes aMonoid
and kicks you back a constructor that is fixed to that Monoid like:Writer (Sum b) a
Also for Maybe, it also takes an internal UnionType and if it is not the UnionType, it delegates to
Maybe.of
(which is basicallyMaybe.Just
)Good 👁 tho.
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.
Actually a better example to highlight the difference would be
IO
.You can only construct an
IO
with a function. BUTof
will take anything you pass it and not check it at all and give you back anIO
, that when run, returns whatever it was you passedof