mirror of
https://github.com/flynx/types.js.git
synced 2025-10-28 10:00:08 +00:00
added filter/map/reduce to Set -- odd that I did not notice they were missing untill now...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
993faa672d
commit
228f7f746e
24
Set.js
24
Set.js
@ -8,11 +8,29 @@
|
||||
/*********************************************************************/
|
||||
|
||||
var object = require('ig-object')
|
||||
var stoppable = require('ig-stoppable')
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
// Wrap .map(..) / .filter(..) / .reduce(..) / .. to support STOP...
|
||||
//
|
||||
// NOTE: internally these are implemented as for-of loops (./generator.js)
|
||||
var stoppableSet = function(iter){
|
||||
return function(func){
|
||||
return new Set([...this][iter](...arguments)) } }
|
||||
var stoppableValue = function(iter, no_return=false){
|
||||
return function(func){
|
||||
var res = [...this][iter](...arguments)
|
||||
return no_return ?
|
||||
undefined
|
||||
: res } }
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
var SetProtoMixin =
|
||||
module.SetProtoMixin =
|
||||
object.Mixin('SetMixin', 'soft', {
|
||||
@ -110,6 +128,12 @@ object.Mixin('SetMixin', 'soft', {
|
||||
this.sort(order)
|
||||
|
||||
return removed },
|
||||
|
||||
filter: stoppableSet('filter'),
|
||||
map: stoppableSet('map'),
|
||||
reduce: stoppableValue('reduce'),
|
||||
reduceRight: stoppableValue('reduceRight'),
|
||||
forEach: stoppableValue('map', true),
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "6.18.0",
|
||||
"version": "6.19.0",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user