-
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.
* 🔧 typo in specs `Semigoup` * add Last Monoid and transformations
- Loading branch information
Showing
29 changed files
with
1,153 additions
and
12 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
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
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
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
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
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
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,73 @@ | ||
/** @license ISC License (c) copyright 2017 original and current authors */ | ||
/** @author Ian Hofmann-Hicks (evil) */ | ||
|
||
const _implements = require('../internal/implements') | ||
const _inspect = require('../internal/inspect') | ||
|
||
const constant = require('../combinators/constant') | ||
const identity = require('../combinators/identity') | ||
const isSameType = require('../predicates/isSameType') | ||
|
||
const Maybe = require('../crocks/Maybe') | ||
|
||
const _empty = | ||
() => Last(Maybe.Nothing()) | ||
|
||
const _type = | ||
constant('Last') | ||
|
||
function Last(x) { | ||
if(!arguments.length) { | ||
throw new TypeError('Last: Requires one argument') | ||
} | ||
|
||
const maybe = | ||
!isSameType(Maybe, x) ? Maybe.of(x) : x.map(identity) | ||
|
||
const value = | ||
constant(maybe) | ||
|
||
const type = | ||
_type | ||
|
||
const empty = | ||
_empty | ||
|
||
const inspect = | ||
constant(`Last(${_inspect(maybe)} )`) | ||
|
||
const option = | ||
maybe.option | ||
|
||
function concat(m) { | ||
if(!isSameType(Last, m)) { | ||
throw new TypeError('Last.concat: Last required') | ||
} | ||
|
||
const n = | ||
m.value().map(identity) | ||
|
||
return Last( | ||
maybe.either( | ||
constant(n), | ||
constant(n.either(constant(maybe), constant(n))) | ||
) | ||
) | ||
} | ||
|
||
return { | ||
concat, empty, inspect, option, type, value | ||
} | ||
} | ||
|
||
Last['@@implements'] = _implements( | ||
[ 'concat', 'empty' ] | ||
) | ||
|
||
Last.empty = | ||
_empty | ||
|
||
Last.type = | ||
_type | ||
|
||
module.exports = Last |
Oops, something went wrong.