-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from transduce/remove-transformer-symbol
Support Official Transformer Protocol cognitect-labs/transducers-js#20
- Loading branch information
Showing
49 changed files
with
617 additions
and
878 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 |
---|---|---|
@@ -1,32 +1,21 @@ | ||
'use strict' | ||
var reduced = require('../core/reduced') | ||
var transducer = require('../core/transducer'), | ||
reduced = require('../core/reduced') | ||
|
||
// Determine whether all of the elements match a truth test. | ||
// Early termination if item does not match predicate. | ||
module.exports = | ||
function every(predicate) { | ||
return function(xf){ | ||
return new Every(predicate, xf) | ||
} | ||
} | ||
function Every(f, xf) { | ||
this.xf = xf | ||
this.f = f | ||
this.found = false | ||
} | ||
Every.prototype.init = function(){ | ||
return this.xf.init() | ||
} | ||
Every.prototype.result = function(result){ | ||
if(!this.found){ | ||
result = this.xf.step(result, true) | ||
} | ||
return this.xf.result(result) | ||
} | ||
Every.prototype.step = function(result, input) { | ||
if(!this.f(input)){ | ||
this.found = true | ||
return reduced(this.xf.step(result, false)) | ||
} | ||
return result | ||
return transducer( | ||
function(step, value, input){ | ||
if(!predicate(input)){ | ||
this.found = true | ||
return reduced(step(value, false)) | ||
} | ||
return value | ||
}, | ||
function(result, value){ | ||
if(!this.found){ | ||
value = this.step(value, true) | ||
} | ||
return result(value) | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,26 +1,14 @@ | ||
'use strict' | ||
var reduced = require('../core/reduced') | ||
var transducer = require('../core/transducer'), | ||
reduced = require('../core/reduced') | ||
|
||
// Return the first value which passes a truth test. Aliased as `detect`. | ||
module.exports = | ||
function find(predicate) { | ||
return function(xf){ | ||
return new Find(predicate, xf) | ||
} | ||
} | ||
function Find(f, xf) { | ||
this.xf = xf | ||
this.f = f | ||
} | ||
Find.prototype.init = function(){ | ||
return this.xf.init() | ||
} | ||
Find.prototype.result = function(result){ | ||
return this.xf.result(result) | ||
} | ||
Find.prototype.step = function(result, input) { | ||
if(this.f(input)){ | ||
result = reduced(this.xf.step(result, input)) | ||
} | ||
return result | ||
return transducer(function(step, value, input){ | ||
if(predicate(input)){ | ||
value = reduced(step(value, input)) | ||
} | ||
return value | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,25 +1,15 @@ | ||
'use strict' | ||
var transducer = require('../core/transducer') | ||
|
||
// Executes f with f(input, idx, result) for forEach item | ||
// passed through transducer without changing the result. | ||
module.exports = | ||
function forEach(f) { | ||
return function(xf){ | ||
return new ForEach(f, xf) | ||
} | ||
} | ||
function ForEach(f, xf) { | ||
this.xf = xf | ||
this.f = f | ||
this.i = 0 | ||
} | ||
ForEach.prototype.init = function(){ | ||
return this.xf.init() | ||
} | ||
ForEach.prototype.result = function(result){ | ||
return this.xf.result(result) | ||
} | ||
ForEach.prototype.step = function(result, input) { | ||
this.f(input, this.i++, result) | ||
return this.xf.step(result, input) | ||
return transducer(function(step, value, input){ | ||
if(this.idx === void 0){ | ||
this.idx = 0 | ||
} | ||
f(input, this.idx++, value) | ||
return step(value, input) | ||
}) | ||
} |
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
Oops, something went wrong.