collect-your-stuff 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -3926
- package/browser/collect-your-stuff.js +912 -549
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +6 -11
- package/dist/collections/arrayable/ArrayElement.js +5 -7
- package/dist/collections/arrayable/Arrayable.d.ts +22 -37
- package/dist/collections/arrayable/Arrayable.js +208 -223
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +9 -14
- package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +19 -36
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
- package/dist/collections/linked-list/LinkedList.d.ts +20 -36
- package/dist/collections/linked-list/LinkedList.js +283 -296
- package/dist/collections/linked-list/Linker.d.ts +8 -13
- package/dist/collections/linked-list/Linker.js +82 -84
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +24 -43
- package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +14 -20
- package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
- package/dist/collections/queue/Queue.d.ts +10 -14
- package/dist/collections/queue/Queue.js +114 -121
- package/dist/collections/queue/Queueable.d.ts +13 -22
- package/dist/collections/queue/Queueable.js +142 -148
- package/dist/collections/queue/TaskQueue.d.ts +8 -17
- package/dist/collections/queue/TaskQueue.js +128 -137
- package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
- package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
- package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +11 -15
- package/dist/collections/stack/Stack.js +122 -129
- package/dist/collections/stack/Stackable.d.ts +9 -16
- package/dist/collections/stack/Stackable.js +81 -85
- package/dist/collections/stack/TaskStack.d.ts +8 -17
- package/dist/collections/stack/TaskStack.js +98 -107
- package/dist/main.d.ts +67 -68
- package/dist/main.js +8 -4
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +4 -4
- package/dist/recipes/ArrayIterator.js +4 -4
- package/dist/recipes/DoubleLinkerIterator.d.ts +3 -3
- package/dist/recipes/DoubleLinkerIterator.js +3 -3
- package/dist/recipes/IsArrayable.d.ts +13 -33
- package/dist/recipes/IsQueue.d.ts +4 -9
- package/dist/recipes/IsScopedCollection.d.ts +27 -0
- package/dist/recipes/IsScopedCollection.js +5 -0
- package/dist/recipes/IsScopedCollection.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +4 -9
- package/dist/recipes/IsTreeNode.d.ts +1 -1
- package/dist/recipes/LinkerIterator.d.ts +3 -3
- package/dist/recipes/LinkerIterator.js +3 -3
- package/dist/recipes/Runnable.d.ts +3 -16
- package/dist/recipes/Runnable.js +3 -9
- package/dist/recipes/TreeLinkerIterator.d.ts +4 -4
- package/dist/recipes/TreeLinkerIterator.js +36 -36
- package/dist/recipes/recipes.d.ts +1 -4
- package/dist/recipes/recipes.js +19 -22
- package/dist/services/parseTree.d.ts +2 -3
- package/dist/services/parseTree.js +23 -24
- package/dist/services/parseTreeNext.d.ts +2 -3
- package/dist/services/parseTreeNext.js +2 -3
- package/dist/services/services.d.ts +1 -4
- package/dist/services/services.js +19 -22
- package/package.json +4 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scoped collection
|
|
3
|
+
*/
|
|
4
|
+
import { IsScopedCollection } from '../../recipes/IsScopedCollection';
|
|
5
|
+
/**
|
|
6
|
+
* A keyed collection, partitioned by an arbitrary scope object: values are stored and looked up by key, with a
|
|
7
|
+
* separate key space per scope. Scopes are held by a WeakMap, so a scope that nothing else references any more
|
|
8
|
+
* takes its whole key space with it - useful anywhere state needs to be tracked per instance of something (a
|
|
9
|
+
* tree's root, a session) without that something needing to hold the state itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ScopedCollection<Scope extends object = object, Key = any, Value = any> implements IsScopedCollection<Scope, Key, Value> {
|
|
12
|
+
private readonly scopes;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Remove a key from a scope's key space.
|
|
16
|
+
* @param scope The scope to remove the key from
|
|
17
|
+
* @param key The key to remove
|
|
18
|
+
* @returns Whether a value was actually removed
|
|
19
|
+
*/
|
|
20
|
+
delete(scope: Scope, key: Key): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Look up a value by key within a scope.
|
|
23
|
+
* @param scope The scope to look within
|
|
24
|
+
* @param key The key to look up
|
|
25
|
+
* @returns The value, or undefined when the scope or key is not present
|
|
26
|
+
*/
|
|
27
|
+
get(scope: Scope, key: Key): Value | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check whether a key exists within a scope.
|
|
30
|
+
* @param scope The scope to look within
|
|
31
|
+
* @param key The key to check
|
|
32
|
+
*/
|
|
33
|
+
has(scope: Scope, key: Key): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Store a value under a key within a scope.
|
|
36
|
+
* @param scope The scope to store the key within
|
|
37
|
+
* @param key The key to store the value under
|
|
38
|
+
* @param value The value to store
|
|
39
|
+
* @returns This collection, so that setting can be chained
|
|
40
|
+
*/
|
|
41
|
+
set(scope: Scope, key: Key, value: Value): this;
|
|
42
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.ScopedCollection = void 0
|
|
7
|
+
require('core-js/modules/esnext.map.delete-all.js')
|
|
8
|
+
require('core-js/modules/esnext.map.every.js')
|
|
9
|
+
require('core-js/modules/esnext.map.filter.js')
|
|
10
|
+
require('core-js/modules/esnext.map.find.js')
|
|
11
|
+
require('core-js/modules/esnext.map.find-key.js')
|
|
12
|
+
require('core-js/modules/esnext.map.includes.js')
|
|
13
|
+
require('core-js/modules/esnext.map.key-of.js')
|
|
14
|
+
require('core-js/modules/esnext.map.map-keys.js')
|
|
15
|
+
require('core-js/modules/esnext.map.map-values.js')
|
|
16
|
+
require('core-js/modules/esnext.map.merge.js')
|
|
17
|
+
require('core-js/modules/esnext.map.reduce.js')
|
|
18
|
+
require('core-js/modules/esnext.map.some.js')
|
|
19
|
+
require('core-js/modules/esnext.map.update.js')
|
|
20
|
+
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
21
|
+
/**
|
|
22
|
+
* A keyed collection, partitioned by an arbitrary scope object: values are stored and looked up by key, with a
|
|
23
|
+
* separate key space per scope. Scopes are held by a WeakMap, so a scope that nothing else references any more
|
|
24
|
+
* takes its whole key space with it - useful anywhere state needs to be tracked per instance of something (a
|
|
25
|
+
* tree's root, a session) without that something needing to hold the state itself.
|
|
26
|
+
*/
|
|
27
|
+
class ScopedCollection {
|
|
28
|
+
constructor () {
|
|
29
|
+
this.scopes = new WeakMap()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Remove a key from a scope's key space.
|
|
34
|
+
* @param scope The scope to remove the key from
|
|
35
|
+
* @param key The key to remove
|
|
36
|
+
* @returns Whether a value was actually removed
|
|
37
|
+
*/
|
|
38
|
+
delete (scope, key) {
|
|
39
|
+
const keyedValues = this.scopes.get(scope)
|
|
40
|
+
return typeof keyedValues === 'undefined' ? false : keyedValues.delete(key)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Look up a value by key within a scope.
|
|
45
|
+
* @param scope The scope to look within
|
|
46
|
+
* @param key The key to look up
|
|
47
|
+
* @returns The value, or undefined when the scope or key is not present
|
|
48
|
+
*/
|
|
49
|
+
get (scope, key) {
|
|
50
|
+
let _a
|
|
51
|
+
return (_a = this.scopes.get(scope)) === null || _a === void 0 ? void 0 : _a.get(key)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check whether a key exists within a scope.
|
|
56
|
+
* @param scope The scope to look within
|
|
57
|
+
* @param key The key to check
|
|
58
|
+
*/
|
|
59
|
+
has (scope, key) {
|
|
60
|
+
let _a, _b
|
|
61
|
+
return (_b = (_a = this.scopes.get(scope)) === null || _a === void 0 ? void 0 : _a.has(key)) !== null && _b !== void 0 ? _b : false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Store a value under a key within a scope.
|
|
66
|
+
* @param scope The scope to store the key within
|
|
67
|
+
* @param key The key to store the value under
|
|
68
|
+
* @param value The value to store
|
|
69
|
+
* @returns This collection, so that setting can be chained
|
|
70
|
+
*/
|
|
71
|
+
set (scope, key, value) {
|
|
72
|
+
let keyedValues = this.scopes.get(scope)
|
|
73
|
+
if (typeof keyedValues === 'undefined') {
|
|
74
|
+
keyedValues = new Map()
|
|
75
|
+
this.scopes.set(scope, keyedValues)
|
|
76
|
+
}
|
|
77
|
+
keyedValues.set(key, value)
|
|
78
|
+
return this
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.ScopedCollection = ScopedCollection
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ScopedCollection=void 0,require("core-js/modules/esnext.map.delete-all.js"),require("core-js/modules/esnext.map.every.js"),require("core-js/modules/esnext.map.filter.js"),require("core-js/modules/esnext.map.find.js"),require("core-js/modules/esnext.map.find-key.js"),require("core-js/modules/esnext.map.includes.js"),require("core-js/modules/esnext.map.key-of.js"),require("core-js/modules/esnext.map.map-keys.js"),require("core-js/modules/esnext.map.map-values.js"),require("core-js/modules/esnext.map.merge.js"),require("core-js/modules/esnext.map.reduce.js"),require("core-js/modules/esnext.map.some.js"),require("core-js/modules/esnext.map.update.js"),require("core-js/modules/esnext.weak-map.delete-all.js");class ScopedCollection{constructor(){this.scopes=new WeakMap}delete(e,s){const o=this.scopes.get(e);return void 0!==o&&o.delete(s)}get(e,s){var o;return null===(o=this.scopes.get(e))||void 0===o?void 0:o.get(s)}has(e,s){var o,r;return null!==(r=null===(o=this.scopes.get(e))||void 0===o?void 0:o.has(s))&&void 0!==r&&r}set(e,s,o){let r=this.scopes.get(e);return void 0===r&&(r=new Map,this.scopes.set(e,r)),r.set(s,o),this}}exports.ScopedCollection=ScopedCollection;
|
|
@@ -12,53 +12,49 @@ export declare class Stack<T = any> implements IsStack<T>, Iterable<T> {
|
|
|
12
12
|
private readonly linkerClass;
|
|
13
13
|
/**
|
|
14
14
|
* Instantiate the stack, optionally with a list of items to start from.
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
15
|
+
* @param stackedList The list of linkers to start in this stack (the first is the top)
|
|
16
|
+
* @param listClass The type of list to create when no stacked list is given
|
|
17
|
+
* @param linkerClass The class used to hold each stacked item
|
|
18
18
|
*/
|
|
19
19
|
constructor(stackedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
20
|
/**
|
|
21
21
|
* Check whether the stack has no items.
|
|
22
|
-
* @return {boolean}
|
|
23
22
|
*/
|
|
24
23
|
empty(): boolean;
|
|
25
24
|
/**
|
|
26
25
|
* Look at the item on the top of the stack, without removing it.
|
|
27
|
-
* @
|
|
26
|
+
* @returns The item, or null when the stack is empty
|
|
28
27
|
*/
|
|
29
28
|
peek(): T | null;
|
|
30
29
|
/**
|
|
31
30
|
* Take the item from the top of the stack.
|
|
32
|
-
* @
|
|
31
|
+
* @returns The item, or null when the stack is empty
|
|
33
32
|
*/
|
|
34
33
|
pop(): T | null;
|
|
35
34
|
/**
|
|
36
35
|
* Add an item to the top of the stack.
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
36
|
+
* @param data The item to add
|
|
37
|
+
* @returns This stack, so that adding can be chained
|
|
39
38
|
*/
|
|
40
39
|
push(data: T): this;
|
|
41
40
|
/**
|
|
42
41
|
* Count the items in the stack.
|
|
43
|
-
* @return {number}
|
|
44
42
|
*/
|
|
45
43
|
size(): number;
|
|
46
44
|
/**
|
|
47
45
|
* The item on the top of the stack (the same as peek).
|
|
48
|
-
* @
|
|
46
|
+
* @returns The item, or null when the stack is empty
|
|
49
47
|
*/
|
|
50
48
|
top(): T | null;
|
|
51
49
|
/**
|
|
52
50
|
* Iterate over the items from the top of the stack to the bottom, without removing them.
|
|
53
|
-
* @return {Iterator}
|
|
54
51
|
*/
|
|
55
52
|
[Symbol.iterator](): Iterator<T>;
|
|
56
53
|
/**
|
|
57
54
|
* Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @returns {Stack}
|
|
55
|
+
* @param values The items to stack
|
|
56
|
+
* @param listClass The type of list used to store the items
|
|
57
|
+
* @param linkerClass The class used to hold each stacked item
|
|
62
58
|
*/
|
|
63
59
|
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Stack<T_1>;
|
|
64
60
|
}
|
|
@@ -1,129 +1,122 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Stack = void 0
|
|
7
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
-
const _Linker = require('../linked-list/Linker')
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
exports.Stack = Stack
|
|
125
|
-
Stack.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
|
|
126
|
-
const stack = new Stack(null, listClass, linkerClass)
|
|
127
|
-
values.forEach(value => stack.push(value))
|
|
128
|
-
return stack
|
|
129
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Stack = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
+
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
+
const _Linker = require('../linked-list/Linker')
|
|
11
|
+
/**
|
|
12
|
+
* stack.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
|
|
17
|
+
* be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
|
|
18
|
+
* time. To stack tasks which are run as they are taken use TaskStack.
|
|
19
|
+
*/
|
|
20
|
+
class Stack {
|
|
21
|
+
/**
|
|
22
|
+
* Instantiate the stack, optionally with a list of items to start from.
|
|
23
|
+
* @param stackedList The list of linkers to start in this stack (the first is the top)
|
|
24
|
+
* @param listClass The type of list to create when no stacked list is given
|
|
25
|
+
* @param linkerClass The class used to hold each stacked item
|
|
26
|
+
*/
|
|
27
|
+
constructor (stackedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
|
|
28
|
+
this.linkerClass = linkerClass
|
|
29
|
+
this.stackedList = stackedList === null ? new listClass(linkerClass) : stackedList
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Check whether the stack has no items.
|
|
34
|
+
*/
|
|
35
|
+
empty () {
|
|
36
|
+
return this.size() <= 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Look at the item on the top of the stack, without removing it.
|
|
41
|
+
* @returns The item, or null when the stack is empty
|
|
42
|
+
*/
|
|
43
|
+
peek () {
|
|
44
|
+
const top = this.stackedList.first
|
|
45
|
+
return top === null || typeof top === 'undefined' ? null : top.data
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Take the item from the top of the stack.
|
|
50
|
+
* @returns The item, or null when the stack is empty
|
|
51
|
+
*/
|
|
52
|
+
pop () {
|
|
53
|
+
const top = this.stackedList.first
|
|
54
|
+
if (top === null || typeof top === 'undefined') {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
this.stackedList.remove(top)
|
|
58
|
+
return top.data
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Add an item to the top of the stack.
|
|
63
|
+
* @param data The item to add
|
|
64
|
+
* @returns This stack, so that adding can be chained
|
|
65
|
+
*/
|
|
66
|
+
push (data) {
|
|
67
|
+
// The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
|
|
68
|
+
// settings (they have a data property) as such, and a stack must give back exactly what it was given
|
|
69
|
+
this.stackedList.prepend(new this.linkerClass({
|
|
70
|
+
data
|
|
71
|
+
}))
|
|
72
|
+
return this
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Count the items in the stack.
|
|
77
|
+
*/
|
|
78
|
+
size () {
|
|
79
|
+
return this.stackedList.length
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The item on the top of the stack (the same as peek).
|
|
84
|
+
* @returns The item, or null when the stack is empty
|
|
85
|
+
*/
|
|
86
|
+
top () {
|
|
87
|
+
return this.peek()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Iterate over the items from the top of the stack to the bottom, without removing them.
|
|
92
|
+
*/
|
|
93
|
+
[Symbol.iterator] () {
|
|
94
|
+
const linkers = this.stackedList[Symbol.iterator]()
|
|
95
|
+
return {
|
|
96
|
+
next: () => {
|
|
97
|
+
const result = linkers.next()
|
|
98
|
+
return result.done
|
|
99
|
+
? {
|
|
100
|
+
done: true,
|
|
101
|
+
value: undefined
|
|
102
|
+
}
|
|
103
|
+
: {
|
|
104
|
+
done: false,
|
|
105
|
+
value: result.value.data
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
|
|
113
|
+
* @param values The items to stack
|
|
114
|
+
* @param listClass The type of list used to store the items
|
|
115
|
+
* @param linkerClass The class used to hold each stacked item
|
|
116
|
+
*/
|
|
117
|
+
exports.Stack = Stack
|
|
118
|
+
Stack.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
|
|
119
|
+
const stack = new Stack(null, listClass, linkerClass)
|
|
120
|
+
values.forEach(value => stack.push(value))
|
|
121
|
+
return stack
|
|
122
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
2
|
+
* stack.
|
|
6
3
|
*/
|
|
7
4
|
import { IsRunnable } from '../../recipes/Runnable';
|
|
8
5
|
import { IsLinker } from '../../recipes/IsLinker';
|
|
@@ -19,10 +16,10 @@ export declare class Stackable implements IsLinker, IsRunnable {
|
|
|
19
16
|
next: Stackable | null;
|
|
20
17
|
/**
|
|
21
18
|
* Create a stackable item that can be used in a stack.
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
19
|
+
* @param stackData The settings for the new stackable.
|
|
20
|
+
* @param stackData.task The data to be stored in this stackable
|
|
21
|
+
* @param stackData.next The reference to the next stackable if any
|
|
22
|
+
* @param stackData.ready Indicate if the stackable is ready to run
|
|
26
23
|
*/
|
|
27
24
|
constructor({ task, next, ready }?: {
|
|
28
25
|
task?: any;
|
|
@@ -31,26 +28,22 @@ export declare class Stackable implements IsLinker, IsRunnable {
|
|
|
31
28
|
});
|
|
32
29
|
/**
|
|
33
30
|
* Retrieve the data which should be formed as a task.
|
|
34
|
-
* @return {*}
|
|
35
31
|
*/
|
|
36
32
|
get task(): any;
|
|
37
33
|
/**
|
|
38
34
|
* Run the stacked task.
|
|
39
|
-
* @return {*}
|
|
40
35
|
*/
|
|
41
36
|
run(): any;
|
|
42
37
|
/**
|
|
43
38
|
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @return {Stackable}
|
|
39
|
+
* @param stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
40
|
+
* @param classType Provide the type of IsLinker to use.
|
|
47
41
|
*/
|
|
48
42
|
static make: (stackable: Stackable | any, classType?: any) => Stackable;
|
|
49
43
|
/**
|
|
50
44
|
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @returns {{head: Stackable, tail: Stackable}}
|
|
45
|
+
* @param values Provide an array of data that will be converted to a chain of stackable linkers.
|
|
46
|
+
* @param classType Provide the type of IsLinker to use.
|
|
54
47
|
*/
|
|
55
48
|
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
56
49
|
head: IsLinker;
|