-
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.
- Loading branch information
Showing
4 changed files
with
289 additions
and
5 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
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,137 @@ | ||
--- | ||
title: "Max" | ||
description: "Max Monoid" | ||
layout: "guide" | ||
weight: 70 | ||
--- | ||
|
||
```haskell | ||
Max Number | ||
``` | ||
|
||
`Max` is a `Monoid` that will combines (2) `Number`s, resulting in the largest | ||
of the two. | ||
|
||
```javascript | ||
const Max = require('crocks/Max') | ||
const mconcat = require('crocks/helpers/mconcat') | ||
|
||
Max(76) | ||
//=> Max 76 | ||
|
||
mconcat(Max, [ 95, 102, 56 ]) | ||
//=> Max 102 | ||
|
||
Max(100) | ||
.concat(Max(10)) | ||
//=> Max 100 | ||
|
||
Max.empty() | ||
.concat(Max(100)) | ||
//=> Max 100 | ||
``` | ||
|
||
<article id="topic-implements"> | ||
|
||
## Implements | ||
|
||
`Semigroup`, `Monoid` | ||
|
||
</article> | ||
|
||
<article id="topic-constructor"> | ||
|
||
## Constructor Methods | ||
|
||
#### empty | ||
|
||
```haskell | ||
Max.empty :: () -> Max | ||
``` | ||
|
||
`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 `Max` the result of `empty` is `-Infinity`. `empty` is available on | ||
both the Constructor and the Instance for convenience. | ||
|
||
```javascript | ||
const Max = require('crocks/Max') | ||
|
||
Max.empty() | ||
//=> Max -Infinity | ||
|
||
Max.empty() | ||
.concat(Max.empty()) | ||
//=> Max -Infinity | ||
|
||
Max(32) | ||
.concat(Max.empty()) | ||
//=> Max 32 | ||
|
||
Max.empty() | ||
.concat(Max(34)) | ||
//=> Max 34 | ||
``` | ||
|
||
</article> | ||
|
||
<article id="topic-instance"> | ||
|
||
## Instance Methods | ||
|
||
#### concat | ||
|
||
```haskell | ||
Max ~> Max -> Max | ||
``` | ||
|
||
`concat` is used to combine (2) `Semigroup`s of the same type under an | ||
operation specified by the `Semigroup`. In the case of `Max`, it will result | ||
in the largest of the (2) `Number`s. | ||
|
||
```javascript | ||
const Max = require('crocks/Max') | ||
|
||
Max(23) | ||
.concat(Max(13)) | ||
//=> Max 23 | ||
|
||
Max(-23) | ||
.concat(Max(-32)) | ||
//=> Max -23 | ||
|
||
Max.empty() | ||
.concat(Max(Infinity)) | ||
//=> Max Infinity | ||
``` | ||
|
||
#### valueOf | ||
|
||
```haskell | ||
Max ~> () -> Number | ||
``` | ||
|
||
`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 a `Max` instance | ||
will result in the underlying `Number`. | ||
|
||
```javascript | ||
const Max = require('crocks/Max') | ||
|
||
Max(4) | ||
.valueOf() | ||
//=> 4 | ||
|
||
Max.empty() | ||
.valueOf() | ||
//=> -Infinity | ||
|
||
Max(34) | ||
.concat(Max(21)) | ||
.valueOf() | ||
//=> 34 | ||
``` | ||
|
||
</article> |
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,137 @@ | ||
--- | ||
title: "Min" | ||
description: "Min Monoid" | ||
layout: "guide" | ||
weight: 80 | ||
--- | ||
|
||
```haskell | ||
Min Number | ||
``` | ||
|
||
`Min` is a `Monoid` that will combines (2) `Number`s, resulting in the smallest | ||
of the two. | ||
|
||
```javascript | ||
const Min = require('crocks/Min') | ||
const mconcat = require('crocks/helpers/mconcat') | ||
|
||
Min(76) | ||
//=> Min 76 | ||
|
||
mconcat(Min, [ 95, 12, 56 ]) | ||
//=> Min 12 | ||
|
||
Min(100) | ||
.concat(Min(10)) | ||
//=> Min 10 | ||
|
||
Min.empty() | ||
.concat(Min(100)) | ||
//=> Min 100 | ||
``` | ||
|
||
<article id="topic-implements"> | ||
|
||
## Implements | ||
|
||
`Semigroup`, `Monoid` | ||
|
||
</article> | ||
|
||
<article id="topic-constructor"> | ||
|
||
## Constructor Methods | ||
|
||
#### empty | ||
|
||
```haskell | ||
Min.empty :: () -> Min | ||
``` | ||
|
||
`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 `Min` the result of `empty` is `Infinity`. `empty` is available on | ||
both the Constructor and the Instance for convenience. | ||
|
||
```javascript | ||
const Min = require('crocks/Min') | ||
|
||
Min.empty() | ||
//=> Min Infinity | ||
|
||
Min.empty() | ||
.concat(Min.empty()) | ||
//=> Min Infinity | ||
|
||
Min(32) | ||
.concat(Min.empty()) | ||
//=> Min 32 | ||
|
||
Min.empty() | ||
.concat(Min(34)) | ||
//=> Min 34 | ||
``` | ||
|
||
</article> | ||
|
||
<article id="topic-instance"> | ||
|
||
## Instance Methods | ||
|
||
#### concat | ||
|
||
```haskell | ||
Min ~> Min -> Min | ||
``` | ||
|
||
`concat` is used to combine (2) `Semigroup`s of the same type under an | ||
operation specified by the `Semigroup`. In the case of `Min`, it will result | ||
in the smallest of the (2) `Number`s. | ||
|
||
```javascript | ||
const Min = require('crocks/Min') | ||
|
||
Min(50) | ||
.concat(Min(24)) | ||
//=> Min 24 | ||
|
||
Min(-120) | ||
.concat(Min(-50)) | ||
//=> Min -120 | ||
|
||
Min.empty() | ||
.concat(Min(-Infinity)) | ||
//=> Min -Infinity | ||
``` | ||
|
||
#### valueOf | ||
|
||
```haskell | ||
Min ~> () -> Number | ||
``` | ||
|
||
`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 a `Min` instance | ||
will result in the underlying `Number`. | ||
|
||
```javascript | ||
const Min = require('crocks/Min') | ||
|
||
Min(33) | ||
.valueOf() | ||
//=> 33 | ||
|
||
Min.empty() | ||
.valueOf() | ||
//=> Infinity | ||
|
||
Min(35) | ||
.concat(Min(20)) | ||
.valueOf() | ||
//=> 20 | ||
``` | ||
|
||
</article> |
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