-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Alt, Plus and Alternative specs (#197)
- refactor tests - 'id.js' moved to 'internal/'
- Loading branch information
1 parent
79ff3a3
commit 9ca844c
Showing
18 changed files
with
374 additions
and
154 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
'use strict'; | ||
|
||
const {tagged} = require('daggy'); | ||
|
||
const fl = require('..'); | ||
const {equality} = require('./func'); | ||
|
||
const Compose = module.exports = tagged('c'); | ||
Compose[fl.of] = Compose; | ||
Compose.prototype[fl.ap] = function(f) { | ||
return Compose(this.c[fl.ap](f.c[fl.map](u => y => y[fl.ap](u)))); | ||
}; | ||
Compose.prototype[fl.map] = function(f) { | ||
return Compose(this.c[fl.map](y => y[fl.map](f))); | ||
}; | ||
Compose.prototype[fl.equals] = function(x) { | ||
return equality(this.c, x.c); | ||
}; |
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,8 @@ | ||
'use strict'; | ||
|
||
const fl = require('../'); | ||
const equality = (x, y) => typeof x[fl.equals] === 'function' ? x[fl.equals](y) : x === y; | ||
|
||
module.exports = { | ||
equality, | ||
}; |
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,15 @@ | ||
'use strict'; | ||
|
||
const patch = require('./patch'); | ||
const Id = require('./id'); | ||
const Sum = require('./string_sum'); | ||
const Compose = require('./compose'); | ||
const {equality} = require('./func'); | ||
|
||
module.exports = { | ||
Id, | ||
Sum, | ||
Compose, | ||
equality, | ||
patch, | ||
}; |
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,29 @@ | ||
'use strict'; | ||
|
||
const fl = require('..'); | ||
|
||
module.exports = () => { | ||
String.prototype[fl.concat] = String.prototype.concat; | ||
Array.prototype[fl.equals] = function(y) { | ||
return this.length === y.length && this.join('') === y.join(''); | ||
}; | ||
Array.prototype[fl.map] = Array.prototype.map; | ||
Array.prototype[fl.ap] = function(fs) { | ||
return fs[fl.chain](f => this.map(f)); | ||
}; | ||
Array.prototype[fl.chain] = function(f) { | ||
return [].concat(this.map(f)); | ||
}; | ||
Array.prototype[fl.reduce] = Array.prototype.reduce; | ||
Array.prototype[fl.concat] = Array.prototype.concat; | ||
Array.prototype[fl.traverse] = function(f, p) { | ||
return this.map(f)[fl.reduce]( | ||
(ys, x) => ys[fl.ap](x[fl.map](y => z => z[fl.concat](y))), | ||
p([]) | ||
); | ||
}; | ||
Array.prototype[fl.alt] = function(b) { | ||
return this.concat(b); | ||
}; | ||
Array[fl.zero] = () => []; | ||
}; |
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,20 @@ | ||
'use strict'; | ||
|
||
const {tagged} = require('daggy'); | ||
|
||
const fl = require('..'); | ||
const {equality} = require('./func'); | ||
|
||
// Special type of sum for the type of string. | ||
const Sum = module.exports = tagged('v'); | ||
Sum[fl.of] = Sum; | ||
Sum[fl.empty] = () => Sum(''); | ||
Sum.prototype[fl.map] = function(f) { | ||
return Sum(f(this.v)); | ||
}; | ||
Sum.prototype[fl.concat] = function(x) { | ||
return Sum(this.v + x.v); | ||
}; | ||
Sum.prototype[fl.equals] = function(x) { | ||
return equality(this.v, x.v); | ||
}; |
Oops, something went wrong.