mirror of
https://github.com/flynx/types.js.git
synced 2025-12-20 18:31:39 +00:00
cleanup and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
71b7bbfe35
commit
6de5cfbe1a
15
Array.js
15
Array.js
@ -2,6 +2,10 @@
|
||||
*
|
||||
*
|
||||
*
|
||||
* XXX move .zip(..) here from diff.js
|
||||
* XXX do we need .at(..) / .to(..) methods here and in Map/Set/...???
|
||||
*
|
||||
*
|
||||
**********************************************/ /* c8 ignore next 2 */
|
||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||
(function(require){ var module={} // make module AMD/node compatible...
|
||||
@ -12,9 +16,6 @@
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
// XXX move .zip(..) here from diff.js
|
||||
|
||||
|
||||
// Array.prototype.flat polyfill...
|
||||
//
|
||||
// NOTE: .flat(..) is not yet supported in IE/Edge...
|
||||
@ -129,6 +130,9 @@ Array.prototype.setCmp = function(other){
|
||||
//
|
||||
// NOTE: if an item is in the array multiple times only the first index
|
||||
// is used...
|
||||
//
|
||||
// XXX should this extend/patch .sort(..)???
|
||||
// ...currently do not see a clean way to do this...
|
||||
Array.prototype.sortAs = function(other){
|
||||
// NOTE: the memory overhead here is better than the time overhead
|
||||
// when using .indexOf(..)...
|
||||
@ -148,7 +152,10 @@ Array.prototype.sortAs = function(other){
|
||||
|
||||
// Same as .sortAs(..) but will not change indexes of items not in other...
|
||||
//
|
||||
// XXX not sure if this is the best way to do this...
|
||||
// Example:
|
||||
// ['a', 3, 'b', 1, 2, 'c']
|
||||
// .inplaceSortAs([1, 2, 3, 3]) // -> ['a', 1, 'b', 2, 3, 'c']
|
||||
//
|
||||
Array.prototype.inplaceSortAs = function(other){
|
||||
// sort only the intersection...
|
||||
var sorted = this
|
||||
|
||||
7
Map.js
7
Map.js
@ -13,8 +13,15 @@
|
||||
/*********************************************************************/
|
||||
|
||||
// NOTE: we do not touch .__keys here as no renaming is ever done...
|
||||
//
|
||||
// XXX this essentially rewrites the whole map, is there a faster/better
|
||||
// way to do this???
|
||||
// ...one way would be to decouple order from the container, i.e.
|
||||
// store the order in a separate attr/prop but this would require
|
||||
// a whole new set of ordered "type" that would overload every single
|
||||
// iteration method, not sure if this is a good idea untill we
|
||||
// reach a state whe JS "shuffles" (index-orders) its containers
|
||||
// (a-la Python)
|
||||
Map.prototype.sort = function(keys){
|
||||
keys = (typeof(keys) == 'function'
|
||||
|| keys === undefined) ?
|
||||
|
||||
10
Set.js
10
Set.js
@ -16,13 +16,17 @@
|
||||
Set.prototype.unite = function(other){
|
||||
return new Set([...this, ...other]) }
|
||||
Set.prototype.intersect = function(other){
|
||||
var test = other.has ? 'has' : 'includes'
|
||||
var test = other.has ?
|
||||
'has'
|
||||
: 'includes'
|
||||
return new Set([...this]
|
||||
.filter(function(e){ return other[test](e) })) }
|
||||
.filter(function(e){
|
||||
return other[test](e) })) }
|
||||
Set.prototype.subtract = function(other){
|
||||
other = new Set(other)
|
||||
return new Set([...this]
|
||||
.filter(function(e){ return !other.has(e) })) }
|
||||
.filter(function(e){
|
||||
return !other.has(e) })) }
|
||||
|
||||
|
||||
Map.prototype.sort = function(keys){
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
*
|
||||
*
|
||||
*
|
||||
**********************************************/ /* c8 ignore next 2 */
|
||||
***********************************************/ /* c8 ignore next 2 */
|
||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||
(function(require){ var module={} // make module AMD/node compatible...
|
||||
/*********************************************************************/
|
||||
@ -27,7 +27,6 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
|
||||
// ...
|
||||
// ])
|
||||
//
|
||||
// XXX should .__keys_index be non-enumerable???
|
||||
__keys_index: null,
|
||||
get __keys(){
|
||||
return (this.__keys_index =
|
||||
@ -45,7 +44,8 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
|
||||
this.__reverse_index || new Map()) },
|
||||
|
||||
|
||||
// Patter to be used to generate unique key...
|
||||
// Pattern to be used to generate unique key...
|
||||
//
|
||||
__key_pattern__: '$KEY ($COUNT)',
|
||||
|
||||
// If true then a value can not be stored under the same key more
|
||||
@ -147,7 +147,7 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
|
||||
// items in sequence, this may be slow and trigger lots of write
|
||||
// observer callbacks. to avoid this use .unOrderedRename(..)
|
||||
// XXX do not see how can we avoid rewriting the map if we want to
|
||||
// keep order...
|
||||
// keep the order...
|
||||
orderedRename: function(from, to, return_key=false){
|
||||
var keys = [...this.keys()]
|
||||
// rename the element...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user