2020-10-04 04:10:08 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2020-10-06 01:32:33 +03:00
|
|
|
**********************************************/ /* c8 ignore next 2 */
|
2020-10-04 04:10:08 +03:00
|
|
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
|
|
|
|
(function(require){ var module={} // make module AMD/node compatible...
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
2020-11-22 23:50:05 +03:00
|
|
|
var object = require('ig-object')
|
2020-10-04 04:10:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
2020-11-22 23:50:05 +03:00
|
|
|
var SetProtoMixin =
|
|
|
|
|
module.SetProtoMixin =
|
|
|
|
|
object.Mixin('SetMixin', 'soft', {
|
|
|
|
|
// Set set operation shorthands...
|
|
|
|
|
unite: function(other=[]){
|
|
|
|
|
return new Set([...this, ...other]) },
|
|
|
|
|
intersect: function(other){
|
|
|
|
|
var test = other.has ?
|
|
|
|
|
'has'
|
|
|
|
|
: 'includes'
|
|
|
|
|
return new Set([...this]
|
|
|
|
|
.filter(function(e){
|
|
|
|
|
return other[test](e) })) },
|
|
|
|
|
subtract: function(other=[]){
|
|
|
|
|
other = new Set(other)
|
|
|
|
|
return new Set([...this]
|
|
|
|
|
.filter(function(e){
|
|
|
|
|
return !other.has(e) })) },
|
|
|
|
|
|
2021-04-03 02:11:02 +03:00
|
|
|
sort: function(values=[]){
|
|
|
|
|
values = (typeof(values) == 'function'
|
|
|
|
|
|| values === undefined) ?
|
|
|
|
|
[...this].sort(values)
|
|
|
|
|
: values
|
2020-11-22 23:50:05 +03:00
|
|
|
var del = this.delete.bind(this)
|
|
|
|
|
var add = this.add.bind(this)
|
2021-04-03 02:11:02 +03:00
|
|
|
new Set([...values, ...this])
|
2020-11-22 23:50:05 +03:00
|
|
|
.forEach(function(e){
|
|
|
|
|
if(this.has(e)){
|
|
|
|
|
del(e)
|
|
|
|
|
add(e) } }.bind(this))
|
|
|
|
|
return this },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetProtoMixin(Set.prototype)
|
2020-10-07 16:46:59 +03:00
|
|
|
|
|
|
|
|
|
2020-10-04 04:10:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* vim:set ts=4 sw=4 : */ return module })
|