collect-your-stuff 1.3.2 → 2.0.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.
Files changed (34) hide show
  1. package/dist/collections/arrayable/Arrayable.d.ts +2 -2
  2. package/dist/collections/arrayable/Arrayable.js +10 -0
  3. package/dist/collections/arrayable/Arrayable.min.js +1 -1
  4. package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +14 -8
  5. package/dist/collections/doubly-linked-list/DoublyLinkedList.js +91 -56
  6. package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
  7. package/dist/collections/linked-list/LinkedList.d.ts +14 -3
  8. package/dist/collections/linked-list/LinkedList.js +76 -32
  9. package/dist/collections/linked-list/LinkedList.min.js +1 -1
  10. package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +9 -3
  11. package/dist/collections/linked-tree-list/LinkedTreeList.js +19 -21
  12. package/dist/collections/linked-tree-list/LinkedTreeList.min.js +1 -1
  13. package/dist/collections/queue/Queue.d.ts +35 -42
  14. package/dist/collections/queue/Queue.js +64 -80
  15. package/dist/collections/queue/Queue.min.js +1 -1
  16. package/dist/collections/queue/TaskQueue.d.ts +68 -0
  17. package/dist/collections/queue/TaskQueue.js +137 -0
  18. package/dist/collections/queue/TaskQueue.min.js +1 -0
  19. package/dist/collections/stack/Stack.d.ts +40 -40
  20. package/dist/collections/stack/Stack.js +73 -52
  21. package/dist/collections/stack/Stack.min.js +1 -1
  22. package/dist/collections/stack/TaskStack.d.ts +65 -0
  23. package/dist/collections/stack/TaskStack.js +107 -0
  24. package/dist/collections/stack/TaskStack.min.js +1 -0
  25. package/dist/main.d.ts +7 -1
  26. package/dist/main.js +16 -0
  27. package/dist/main.min.js +1 -1
  28. package/dist/recipes/IsQueue.d.ts +37 -0
  29. package/dist/recipes/IsQueue.js +5 -0
  30. package/dist/recipes/IsQueue.min.js +1 -0
  31. package/dist/recipes/IsStack.d.ts +36 -0
  32. package/dist/recipes/IsStack.js +5 -0
  33. package/dist/recipes/IsStack.min.js +1 -0
  34. package/package.json +1 -1
@@ -1,64 +1,64 @@
1
- /**
2
- * @file stack.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- * @memberOf module:collect-your-stuff
6
- */
7
- import { Stackable } from './Stackable';
1
+ import { Linker } from '../linked-list/Linker';
8
2
  import { IsArrayable } from '../../recipes/IsArrayable';
9
- import { IsLinker } from '../../recipes/IsLinker';
10
- import { completeResponse } from '../../recipes/Runnable';
3
+ import { IsStack } from '../../recipes/IsStack';
11
4
  /**
12
- * Store a collection of items which can only be inserted and removed from the top.
5
+ * A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
6
+ * be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
7
+ * time. To stack tasks which are run as they are taken use TaskStack.
13
8
  */
14
- export declare class Stack {
15
- /** The list which stores the stackables, the first is the top of the stack. */
9
+ export declare class Stack<T = any> implements IsStack<T>, Iterable<T> {
10
+ /** The list which stores the stacked items, the first is the top of the stack. */
16
11
  stackedList: IsArrayable<any>;
17
- private listClass;
18
- private stackableClass;
12
+ private readonly linkerClass;
19
13
  /**
20
- * Instantiate the state with the starter stacked list.
21
- * @param {Iterable|LinkedList} [stackedList=null] The list of stackables to start in this stack.
22
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given.
23
- * @param {Stackable} [stackableClass=Stackable] The class used to wrap stacked items.
14
+ * Instantiate the stack, optionally with a list of items to start from.
15
+ * @param {IsArrayable|null} [stackedList=null] The list of linkers to start in this stack (the first is the top)
16
+ * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given
17
+ * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
24
18
  */
25
- constructor(stackedList?: IsArrayable<any>, listClass?: any, stackableClass?: typeof Stackable);
19
+ constructor(stackedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
26
20
  /**
27
- * Return true if the stack is empty (there are no tasks in the stacked list)
21
+ * Check whether the stack has no items.
28
22
  * @return {boolean}
29
23
  */
30
24
  empty(): boolean;
31
25
  /**
32
- * Take a look at the next stacked task
33
- * @return {Stackable}
34
- */
35
- top(): IsLinker;
36
- /**
37
- * Remove the next stacked task and return it.
38
- * @return {Stackable|null}
26
+ * Look at the item on the top of the stack, without removing it.
27
+ * @return {*|null} The item, or null when the stack is empty
39
28
  */
40
- pop(): Stackable | completeResponse | null;
29
+ peek(): T | null;
41
30
  /**
42
- * Push a stackable task to the top of the stack.
43
- * @param {Stackable|*} stackable Add a new stackable to the top of the stack
31
+ * Take the item from the top of the stack.
32
+ * @return {*|null} The item, or null when the stack is empty
44
33
  */
45
- push(stackable: any): void;
34
+ pop(): T | null;
46
35
  /**
47
- * Remove the next stacked task and return it.
48
- * @return {Stackable|null}
36
+ * Add an item to the top of the stack.
37
+ * @param {*} data The item to add
38
+ * @return {Stack} This stack, so that adding can be chained
49
39
  */
50
- remove(): Stackable | null;
40
+ push(data: T): this;
51
41
  /**
52
- * Get the size of the current stack.
42
+ * Count the items in the stack.
53
43
  * @return {number}
54
44
  */
55
45
  size(): number;
56
46
  /**
57
- * Convert an array to a Stack.
58
- * @param {Array} values An array of values which will be converted to stackables in this queue
59
- * @param {Stackable} stackableClass The class to use for each stackable
60
- * @param {Stack|Iterable} listClass The class to use to manage the stackables
47
+ * The item on the top of the stack (the same as peek).
48
+ * @return {*|null} The item, or null when the stack is empty
49
+ */
50
+ top(): T | null;
51
+ /**
52
+ * Iterate over the items from the top of the stack to the bottom, without removing them.
53
+ * @return {Iterator}
54
+ */
55
+ [Symbol.iterator](): Iterator<T>;
56
+ /**
57
+ * Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
58
+ * @param {Array} [values=[]] The items to stack
59
+ * @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
60
+ * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
61
61
  * @returns {Stack}
62
62
  */
63
- static fromArray: (values?: Array<any>, stackableClass?: typeof Stackable, listClass?: any) => Stack;
63
+ static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Stack<T_1>;
64
64
  }
@@ -4,36 +4,36 @@ Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  })
6
6
  exports.Stack = void 0
7
- var _Stackable = require('./Stackable')
7
+ require('core-js/modules/esnext.iterator.constructor.js')
8
+ require('core-js/modules/esnext.iterator.for-each.js')
8
9
  var _LinkedList = require('../linked-list/LinkedList')
10
+ var _Linker = require('../linked-list/Linker')
9
11
  /**
10
12
  * @file stack.
11
13
  * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @version 1.0.0
14
+ * @version 2.0.0
13
15
  * @memberOf module:collect-your-stuff
14
16
  */
15
17
 
16
18
  /**
17
- * Store a collection of items which can only be inserted and removed from the top.
19
+ * A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
20
+ * be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
21
+ * time. To stack tasks which are run as they are taken use TaskStack.
18
22
  */
19
23
  class Stack {
20
24
  /**
21
- * Instantiate the state with the starter stacked list.
22
- * @param {Iterable|LinkedList} [stackedList=null] The list of stackables to start in this stack.
23
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given.
24
- * @param {Stackable} [stackableClass=Stackable] The class used to wrap stacked items.
25
+ * Instantiate the stack, optionally with a list of items to start from.
26
+ * @param {IsArrayable|null} [stackedList=null] The list of linkers to start in this stack (the first is the top)
27
+ * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given
28
+ * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
25
29
  */
26
- constructor (stackedList = null, listClass = _LinkedList.LinkedList, stackableClass = _Stackable.Stackable) {
27
- this.listClass = listClass
28
- this.stackableClass = stackableClass
29
- if (stackedList === null) {
30
- stackedList = new listClass(stackableClass)
31
- }
32
- this.stackedList = stackedList
30
+ constructor (stackedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
31
+ this.linkerClass = linkerClass
32
+ this.stackedList = stackedList === null ? new listClass(linkerClass) : stackedList
33
33
  }
34
34
 
35
35
  /**
36
- * Return true if the stack is empty (there are no tasks in the stacked list)
36
+ * Check whether the stack has no items.
37
37
  * @return {boolean}
38
38
  */
39
39
  empty () {
@@ -41,66 +41,87 @@ class Stack {
41
41
  }
42
42
 
43
43
  /**
44
- * Take a look at the next stacked task
45
- * @return {Stackable}
44
+ * Look at the item on the top of the stack, without removing it.
45
+ * @return {*|null} The item, or null when the stack is empty
46
46
  */
47
- top () {
48
- return this.stackedList.first
47
+ peek () {
48
+ const top = this.stackedList.first
49
+ return top === null || typeof top === 'undefined' ? null : top.data
49
50
  }
50
51
 
51
52
  /**
52
- * Remove the next stacked task and return it.
53
- * @return {Stackable|null}
53
+ * Take the item from the top of the stack.
54
+ * @return {*|null} The item, or null when the stack is empty
54
55
  */
55
56
  pop () {
56
- const next = this.remove()
57
- if (!next) {
58
- return {
59
- success: 'No more stackable tasks in the stack',
60
- error: false,
61
- context: this.stackedList
62
- }
57
+ const top = this.stackedList.first
58
+ if (top === null || typeof top === 'undefined') {
59
+ return null
63
60
  }
64
- return next.run()
61
+ this.stackedList.remove(top)
62
+ return top.data
65
63
  }
66
64
 
67
65
  /**
68
- * Push a stackable task to the top of the stack.
69
- * @param {Stackable|*} stackable Add a new stackable to the top of the stack
66
+ * Add an item to the top of the stack.
67
+ * @param {*} data The item to add
68
+ * @return {Stack} This stack, so that adding can be chained
70
69
  */
71
- push (stackable) {
72
- this.stackedList.prepend(stackable)
70
+ push (data) {
71
+ // The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
72
+ // settings (they have a data property) as such, and a stack must give back exactly what it was given
73
+ this.stackedList.prepend(new this.linkerClass({
74
+ data
75
+ }))
76
+ return this
73
77
  }
74
78
 
75
79
  /**
76
- * Remove the next stacked task and return it.
77
- * @return {Stackable|null}
80
+ * Count the items in the stack.
81
+ * @return {number}
78
82
  */
79
- remove () {
80
- if (this.empty()) {
81
- return null
82
- }
83
- return this.stackedList.remove(this.stackedList.first)
83
+ size () {
84
+ return this.stackedList.length
84
85
  }
85
86
 
86
87
  /**
87
- * Get the size of the current stack.
88
- * @return {number}
88
+ * The item on the top of the stack (the same as peek).
89
+ * @return {*|null} The item, or null when the stack is empty
89
90
  */
90
- size () {
91
- return this.stackedList.length
91
+ top () {
92
+ return this.peek()
93
+ }
94
+
95
+ /**
96
+ * Iterate over the items from the top of the stack to the bottom, without removing them.
97
+ * @return {Iterator}
98
+ */
99
+ [Symbol.iterator] () {
100
+ const linkers = this.stackedList[Symbol.iterator]()
101
+ return {
102
+ next: () => {
103
+ const result = linkers.next()
104
+ return result.done ? {
105
+ done: true,
106
+ value: undefined
107
+ } : {
108
+ done: false,
109
+ value: result.value.data
110
+ }
111
+ }
112
+ }
92
113
  }
93
114
  }
94
115
  /**
95
- * Convert an array to a Stack.
96
- * @param {Array} values An array of values which will be converted to stackables in this queue
97
- * @param {Stackable} stackableClass The class to use for each stackable
98
- * @param {Stack|Iterable} listClass The class to use to manage the stackables
116
+ * Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
117
+ * @param {Array} [values=[]] The items to stack
118
+ * @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
119
+ * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
99
120
  * @returns {Stack}
100
121
  */
101
122
  exports.Stack = Stack
102
- Stack.fromArray = (values = [], stackableClass = _Stackable.Stackable, listClass = _LinkedList.LinkedList) => {
103
- const list = new listClass(stackableClass)
104
- list.initialize(stackableClass.fromArray(values, stackableClass).head)
105
- return new Stack(list, listClass, stackableClass)
123
+ Stack.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
124
+ const stack = new Stack(null, listClass, linkerClass)
125
+ values.forEach(value => stack.push(value))
126
+ return stack
106
127
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Stack=void 0;var _Stackable=require("./Stackable"),_LinkedList=require("../linked-list/LinkedList");class Stack{constructor(t=null,e=_LinkedList.LinkedList,s=_Stackable.Stackable){this.listClass=e,this.stackableClass=s,null===t&&(t=new e(s)),this.stackedList=t}empty(){return this.size()<=0}top(){return this.stackedList.first}pop(){const t=this.remove();return t?t.run():{success:"No more stackable tasks in the stack",error:!1,context:this.stackedList}}push(t){this.stackedList.prepend(t)}remove(){return this.empty()?null:this.stackedList.remove(this.stackedList.first)}size(){return this.stackedList.length}}exports.Stack=Stack,Stack.fromArray=(t=[],e=_Stackable.Stackable,s=_LinkedList.LinkedList)=>{const i=new s(e);return i.initialize(e.fromArray(t,e).head),new Stack(i,s,e)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Stack=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js");var _LinkedList=require("../linked-list/LinkedList"),_Linker=require("../linked-list/Linker");class Stack{constructor(e=null,t=_LinkedList.LinkedList,s=_Linker.Linker){this.linkerClass=s,this.stackedList=null===e?new t(s):e}empty(){return this.size()<=0}peek(){const e=this.stackedList.first;return null==e?null:e.data}pop(){const e=this.stackedList.first;return null==e?null:(this.stackedList.remove(e),e.data)}push(e){return this.stackedList.prepend(new this.linkerClass({data:e})),this}size(){return this.stackedList.length}top(){return this.peek()}[Symbol.iterator](){const e=this.stackedList[Symbol.iterator]();return{next:()=>{const t=e.next();return t.done?{done:!0,value:void 0}:{done:!1,value:t.value.data}}}}}exports.Stack=Stack,Stack.fromArray=(e=[],t=_LinkedList.LinkedList,s=_Linker.Linker)=>{const r=new Stack(null,t,s);return e.forEach((e=>r.push(e))),r};
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @file task stack.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ * @memberOf module:collect-your-stuff
6
+ */
7
+ import { Stackable } from './Stackable';
8
+ import { IsArrayable } from '../../recipes/IsArrayable';
9
+ import { IsLinker } from '../../recipes/IsLinker';
10
+ import { completeResponse } from '../../recipes/Runnable';
11
+ /**
12
+ * Store a collection of tasks (Stackables) which can only be inserted and removed from the top: pop() takes the task from
13
+ * the top and RUNS it. For a plain last-in-first-out collection of items use Stack.
14
+ */
15
+ export declare class TaskStack {
16
+ /** The list which stores the stackables, the first is the top of the stack. */
17
+ stackedList: IsArrayable<any>;
18
+ private listClass;
19
+ private stackableClass;
20
+ /**
21
+ * Instantiate the state with the starter stacked list.
22
+ * @param {Iterable|LinkedList} [stackedList=null] The list of stackables to start in this stack.
23
+ * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given.
24
+ * @param {Stackable} [stackableClass=Stackable] The class used to wrap stacked items.
25
+ */
26
+ constructor(stackedList?: IsArrayable<any>, listClass?: any, stackableClass?: typeof Stackable);
27
+ /**
28
+ * Return true if the stack is empty (there are no tasks in the stacked list)
29
+ * @return {boolean}
30
+ */
31
+ empty(): boolean;
32
+ /**
33
+ * Take a look at the next stacked task
34
+ * @return {Stackable}
35
+ */
36
+ top(): IsLinker;
37
+ /**
38
+ * Remove the next stacked task and return it.
39
+ * @return {Stackable|null}
40
+ */
41
+ pop(): Stackable | completeResponse | null;
42
+ /**
43
+ * Push a stackable task to the top of the stack.
44
+ * @param {Stackable|*} stackable Add a new stackable to the top of the stack
45
+ */
46
+ push(stackable: any): void;
47
+ /**
48
+ * Remove the next stacked task and return it.
49
+ * @return {Stackable|null}
50
+ */
51
+ remove(): Stackable | null;
52
+ /**
53
+ * Get the size of the current stack.
54
+ * @return {number}
55
+ */
56
+ size(): number;
57
+ /**
58
+ * Convert an array to a TaskStack.
59
+ * @param {Array} values An array of values which will be converted to stackables in this queue
60
+ * @param {Stackable} stackableClass The class to use for each stackable
61
+ * @param {TaskStack|Iterable} listClass The class to use to manage the stackables
62
+ * @returns {TaskStack}
63
+ */
64
+ static fromArray: (values?: Array<any>, stackableClass?: typeof Stackable, listClass?: any) => TaskStack;
65
+ }
@@ -0,0 +1,107 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.TaskStack = void 0
7
+ var _Stackable = require('./Stackable')
8
+ var _LinkedList = require('../linked-list/LinkedList')
9
+ /**
10
+ * @file task stack.
11
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
12
+ * @version 1.0.0
13
+ * @memberOf module:collect-your-stuff
14
+ */
15
+
16
+ /**
17
+ * Store a collection of tasks (Stackables) which can only be inserted and removed from the top: pop() takes the task from
18
+ * the top and RUNS it. For a plain last-in-first-out collection of items use Stack.
19
+ */
20
+ class TaskStack {
21
+ /**
22
+ * Instantiate the state with the starter stacked list.
23
+ * @param {Iterable|LinkedList} [stackedList=null] The list of stackables to start in this stack.
24
+ * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given.
25
+ * @param {Stackable} [stackableClass=Stackable] The class used to wrap stacked items.
26
+ */
27
+ constructor (stackedList = null, listClass = _LinkedList.LinkedList, stackableClass = _Stackable.Stackable) {
28
+ this.listClass = listClass
29
+ this.stackableClass = stackableClass
30
+ if (stackedList === null) {
31
+ stackedList = new listClass(stackableClass)
32
+ }
33
+ this.stackedList = stackedList
34
+ }
35
+
36
+ /**
37
+ * Return true if the stack is empty (there are no tasks in the stacked list)
38
+ * @return {boolean}
39
+ */
40
+ empty () {
41
+ return this.size() <= 0
42
+ }
43
+
44
+ /**
45
+ * Take a look at the next stacked task
46
+ * @return {Stackable}
47
+ */
48
+ top () {
49
+ return this.stackedList.first
50
+ }
51
+
52
+ /**
53
+ * Remove the next stacked task and return it.
54
+ * @return {Stackable|null}
55
+ */
56
+ pop () {
57
+ const next = this.remove()
58
+ if (!next) {
59
+ return {
60
+ success: 'No more stackable tasks in the stack',
61
+ error: false,
62
+ context: this.stackedList
63
+ }
64
+ }
65
+ return next.run()
66
+ }
67
+
68
+ /**
69
+ * Push a stackable task to the top of the stack.
70
+ * @param {Stackable|*} stackable Add a new stackable to the top of the stack
71
+ */
72
+ push (stackable) {
73
+ this.stackedList.prepend(stackable)
74
+ }
75
+
76
+ /**
77
+ * Remove the next stacked task and return it.
78
+ * @return {Stackable|null}
79
+ */
80
+ remove () {
81
+ if (this.empty()) {
82
+ return null
83
+ }
84
+ return this.stackedList.remove(this.stackedList.first)
85
+ }
86
+
87
+ /**
88
+ * Get the size of the current stack.
89
+ * @return {number}
90
+ */
91
+ size () {
92
+ return this.stackedList.length
93
+ }
94
+ }
95
+ /**
96
+ * Convert an array to a TaskStack.
97
+ * @param {Array} values An array of values which will be converted to stackables in this queue
98
+ * @param {Stackable} stackableClass The class to use for each stackable
99
+ * @param {TaskStack|Iterable} listClass The class to use to manage the stackables
100
+ * @returns {TaskStack}
101
+ */
102
+ exports.TaskStack = TaskStack
103
+ TaskStack.fromArray = (values = [], stackableClass = _Stackable.Stackable, listClass = _LinkedList.LinkedList) => {
104
+ const list = new listClass(stackableClass)
105
+ list.initialize(stackableClass.fromArray(values, stackableClass).head)
106
+ return new TaskStack(list, listClass, stackableClass)
107
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TaskStack=void 0;var _Stackable=require("./Stackable"),_LinkedList=require("../linked-list/LinkedList");class TaskStack{constructor(t=null,s=_LinkedList.LinkedList,e=_Stackable.Stackable){this.listClass=s,this.stackableClass=e,null===t&&(t=new s(e)),this.stackedList=t}empty(){return this.size()<=0}top(){return this.stackedList.first}pop(){const t=this.remove();return t?t.run():{success:"No more stackable tasks in the stack",error:!1,context:this.stackedList}}push(t){this.stackedList.prepend(t)}remove(){return this.empty()?null:this.stackedList.remove(this.stackedList.first)}size(){return this.stackedList.length}}exports.TaskStack=TaskStack,TaskStack.fromArray=(t=[],s=_Stackable.Stackable,e=_LinkedList.LinkedList)=>{const i=new e(s);return i.initialize(s.fromArray(t,s).head),new TaskStack(i,e,s)};
package/dist/main.d.ts CHANGED
@@ -16,8 +16,10 @@ import { TreeLinker } from './collections/linked-tree-list/TreeLinker';
16
16
  import { LinkedTreeList } from './collections/linked-tree-list/LinkedTreeList';
17
17
  import { Queueable } from './collections/queue/Queueable';
18
18
  import { Queue } from './collections/queue/Queue';
19
+ import { TaskQueue } from './collections/queue/TaskQueue';
19
20
  import { Stackable } from './collections/stack/Stackable';
20
21
  import { Stack } from './collections/stack/Stack';
22
+ import { TaskStack } from './collections/stack/TaskStack';
21
23
  import { recipes } from './recipes/recipes';
22
24
  import { services } from './services/services';
23
25
  /**
@@ -26,13 +28,15 @@ import { services } from './services/services';
26
28
  * 2. Create a heap (both min and max heap variants) which is similar to binary tree in structure, but tree having its min / max value as root. and it must insert on the left-most lowest level, and removes from root. Be able to easily swap nodes to ensure min / max ordering.
27
29
  * 3. Create a graph type which can have directional and undirectional variants for linking nodes
28
30
  */
29
- export { ArrayElement, Arrayable, DoubleLinker, DoublyLinkedList, Linker, LinkedList, TreeLinker, LinkedTreeList, Queueable, Queue, Stackable, Stack, recipes, services };
31
+ export { ArrayElement, Arrayable, DoubleLinker, DoublyLinkedList, Linker, LinkedList, TreeLinker, LinkedTreeList, Queueable, Queue, TaskQueue, Stackable, Stack, TaskStack, recipes, services };
30
32
  export type { IsArrayable, forEachCallback } from './recipes/IsArrayable';
31
33
  export type { IsDoubleLinker } from './recipes/IsDoubleLinker';
32
34
  export type { IsElement } from './recipes/IsElement';
33
35
  export type { IsLinker } from './recipes/IsLinker';
34
36
  export type { IsTree } from './recipes/IsTree';
35
37
  export type { IsTreeNode } from './recipes/IsTreeNode';
38
+ export type { IsQueue } from './recipes/IsQueue';
39
+ export type { IsStack } from './recipes/IsStack';
36
40
  export type { IsRunnable, completeResponse } from './recipes/Runnable';
37
41
  /**
38
42
  * All methods exported from this module are encapsulated within collect-your-stuff (this default export is the same
@@ -49,8 +53,10 @@ declare const collectYourStuff: {
49
53
  LinkedTreeList: typeof LinkedTreeList;
50
54
  Queueable: typeof Queueable;
51
55
  Queue: typeof Queue;
56
+ TaskQueue: typeof TaskQueue;
52
57
  Stackable: typeof Stackable;
53
58
  Stack: typeof Stack;
59
+ TaskStack: typeof TaskStack;
54
60
  recipes: {
55
61
  ArrayIterator: typeof import("./recipes/ArrayIterator").ArrayIterator;
56
62
  Runnable: typeof import("./recipes/Runnable").Runnable;
package/dist/main.js CHANGED
@@ -69,6 +69,18 @@ Object.defineProperty(exports, 'Stackable', {
69
69
  return _Stackable.Stackable
70
70
  }
71
71
  })
72
+ Object.defineProperty(exports, 'TaskQueue', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _TaskQueue.TaskQueue
76
+ }
77
+ })
78
+ Object.defineProperty(exports, 'TaskStack', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _TaskStack.TaskStack
82
+ }
83
+ })
72
84
  Object.defineProperty(exports, 'TreeLinker', {
73
85
  enumerable: true,
74
86
  get: function () {
@@ -99,8 +111,10 @@ var _TreeLinker = require('./collections/linked-tree-list/TreeLinker')
99
111
  var _LinkedTreeList = require('./collections/linked-tree-list/LinkedTreeList')
100
112
  var _Queueable = require('./collections/queue/Queueable')
101
113
  var _Queue = require('./collections/queue/Queue')
114
+ var _TaskQueue = require('./collections/queue/TaskQueue')
102
115
  var _Stackable = require('./collections/stack/Stackable')
103
116
  var _Stack = require('./collections/stack/Stack')
117
+ var _TaskStack = require('./collections/stack/TaskStack')
104
118
  var _recipes = require('./recipes/recipes')
105
119
  var _services = require('./services/services')
106
120
  /**
@@ -135,8 +149,10 @@ const collectYourStuff = {
135
149
  LinkedTreeList: _LinkedTreeList.LinkedTreeList,
136
150
  Queueable: _Queueable.Queueable,
137
151
  Queue: _Queue.Queue,
152
+ TaskQueue: _TaskQueue.TaskQueue,
138
153
  Stackable: _Stackable.Stackable,
139
154
  Stack: _Stack.Stack,
155
+ TaskStack: _TaskStack.TaskStack,
140
156
  recipes: _recipes.recipes,
141
157
  services: _services.services
142
158
  }
package/dist/main.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ArrayElement",{enumerable:!0,get:function(){return _ArrayElement.ArrayElement}}),Object.defineProperty(exports,"Arrayable",{enumerable:!0,get:function(){return _Arrayable.Arrayable}}),Object.defineProperty(exports,"DoubleLinker",{enumerable:!0,get:function(){return _DoubleLinker.DoubleLinker}}),Object.defineProperty(exports,"DoublyLinkedList",{enumerable:!0,get:function(){return _DoublyLinkedList.DoublyLinkedList}}),Object.defineProperty(exports,"LinkedList",{enumerable:!0,get:function(){return _LinkedList.LinkedList}}),Object.defineProperty(exports,"LinkedTreeList",{enumerable:!0,get:function(){return _LinkedTreeList.LinkedTreeList}}),Object.defineProperty(exports,"Linker",{enumerable:!0,get:function(){return _Linker.Linker}}),Object.defineProperty(exports,"Queue",{enumerable:!0,get:function(){return _Queue.Queue}}),Object.defineProperty(exports,"Queueable",{enumerable:!0,get:function(){return _Queueable.Queueable}}),Object.defineProperty(exports,"Stack",{enumerable:!0,get:function(){return _Stack.Stack}}),Object.defineProperty(exports,"Stackable",{enumerable:!0,get:function(){return _Stackable.Stackable}}),Object.defineProperty(exports,"TreeLinker",{enumerable:!0,get:function(){return _TreeLinker.TreeLinker}}),exports.default=void 0,Object.defineProperty(exports,"recipes",{enumerable:!0,get:function(){return _recipes.recipes}}),Object.defineProperty(exports,"services",{enumerable:!0,get:function(){return _services.services}}),require("core-js/stable");var _ArrayElement=require("./collections/arrayable/ArrayElement"),_Arrayable=require("./collections/arrayable/Arrayable"),_DoubleLinker=require("./collections/doubly-linked-list/DoubleLinker"),_DoublyLinkedList=require("./collections/doubly-linked-list/DoublyLinkedList"),_Linker=require("./collections/linked-list/Linker"),_LinkedList=require("./collections/linked-list/LinkedList"),_TreeLinker=require("./collections/linked-tree-list/TreeLinker"),_LinkedTreeList=require("./collections/linked-tree-list/LinkedTreeList"),_Queueable=require("./collections/queue/Queueable"),_Queue=require("./collections/queue/Queue"),_Stackable=require("./collections/stack/Stackable"),_Stack=require("./collections/stack/Stack"),_recipes=require("./recipes/recipes"),_services=require("./services/services");const collectYourStuff={ArrayElement:_ArrayElement.ArrayElement,Arrayable:_Arrayable.Arrayable,DoubleLinker:_DoubleLinker.DoubleLinker,DoublyLinkedList:_DoublyLinkedList.DoublyLinkedList,Linker:_Linker.Linker,LinkedList:_LinkedList.LinkedList,TreeLinker:_TreeLinker.TreeLinker,LinkedTreeList:_LinkedTreeList.LinkedTreeList,Queueable:_Queueable.Queueable,Queue:_Queue.Queue,Stackable:_Stackable.Stackable,Stack:_Stack.Stack,recipes:_recipes.recipes,services:_services.services};var _default=exports.default=collectYourStuff;"undefined"!=typeof window&&(window.collectYourStuff=collectYourStuff);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ArrayElement",{enumerable:!0,get:function(){return _ArrayElement.ArrayElement}}),Object.defineProperty(exports,"Arrayable",{enumerable:!0,get:function(){return _Arrayable.Arrayable}}),Object.defineProperty(exports,"DoubleLinker",{enumerable:!0,get:function(){return _DoubleLinker.DoubleLinker}}),Object.defineProperty(exports,"DoublyLinkedList",{enumerable:!0,get:function(){return _DoublyLinkedList.DoublyLinkedList}}),Object.defineProperty(exports,"LinkedList",{enumerable:!0,get:function(){return _LinkedList.LinkedList}}),Object.defineProperty(exports,"LinkedTreeList",{enumerable:!0,get:function(){return _LinkedTreeList.LinkedTreeList}}),Object.defineProperty(exports,"Linker",{enumerable:!0,get:function(){return _Linker.Linker}}),Object.defineProperty(exports,"Queue",{enumerable:!0,get:function(){return _Queue.Queue}}),Object.defineProperty(exports,"Queueable",{enumerable:!0,get:function(){return _Queueable.Queueable}}),Object.defineProperty(exports,"Stack",{enumerable:!0,get:function(){return _Stack.Stack}}),Object.defineProperty(exports,"Stackable",{enumerable:!0,get:function(){return _Stackable.Stackable}}),Object.defineProperty(exports,"TaskQueue",{enumerable:!0,get:function(){return _TaskQueue.TaskQueue}}),Object.defineProperty(exports,"TaskStack",{enumerable:!0,get:function(){return _TaskStack.TaskStack}}),Object.defineProperty(exports,"TreeLinker",{enumerable:!0,get:function(){return _TreeLinker.TreeLinker}}),exports.default=void 0,Object.defineProperty(exports,"recipes",{enumerable:!0,get:function(){return _recipes.recipes}}),Object.defineProperty(exports,"services",{enumerable:!0,get:function(){return _services.services}}),require("core-js/stable");var _ArrayElement=require("./collections/arrayable/ArrayElement"),_Arrayable=require("./collections/arrayable/Arrayable"),_DoubleLinker=require("./collections/doubly-linked-list/DoubleLinker"),_DoublyLinkedList=require("./collections/doubly-linked-list/DoublyLinkedList"),_Linker=require("./collections/linked-list/Linker"),_LinkedList=require("./collections/linked-list/LinkedList"),_TreeLinker=require("./collections/linked-tree-list/TreeLinker"),_LinkedTreeList=require("./collections/linked-tree-list/LinkedTreeList"),_Queueable=require("./collections/queue/Queueable"),_Queue=require("./collections/queue/Queue"),_TaskQueue=require("./collections/queue/TaskQueue"),_Stackable=require("./collections/stack/Stackable"),_Stack=require("./collections/stack/Stack"),_TaskStack=require("./collections/stack/TaskStack"),_recipes=require("./recipes/recipes"),_services=require("./services/services");const collectYourStuff={ArrayElement:_ArrayElement.ArrayElement,Arrayable:_Arrayable.Arrayable,DoubleLinker:_DoubleLinker.DoubleLinker,DoublyLinkedList:_DoublyLinkedList.DoublyLinkedList,Linker:_Linker.Linker,LinkedList:_LinkedList.LinkedList,TreeLinker:_TreeLinker.TreeLinker,LinkedTreeList:_LinkedTreeList.LinkedTreeList,Queueable:_Queueable.Queueable,Queue:_Queue.Queue,TaskQueue:_TaskQueue.TaskQueue,Stackable:_Stackable.Stackable,Stack:_Stack.Stack,TaskStack:_TaskStack.TaskStack,recipes:_recipes.recipes,services:_services.services};var _default=exports.default=collectYourStuff;"undefined"!=typeof window&&(window.collectYourStuff=collectYourStuff);
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @file Queue recipe.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ * @memberOf module:collect-your-stuff
6
+ */
7
+ /**
8
+ * Define a first-in-first-out queue: items are added to the back (enqueue) and taken from the front (dequeue).
9
+ * This is the shape which si-funciona's queueManager / queueTimeout expect of a queue.
10
+ */
11
+ export interface IsQueue<T = any> {
12
+ /**
13
+ * Take the item from the front of the queue.
14
+ * @return {T|null} The item, or null when the queue is empty
15
+ */
16
+ dequeue: () => T | null;
17
+ /**
18
+ * Check whether the queue has no items.
19
+ * @return {boolean}
20
+ */
21
+ empty: () => boolean;
22
+ /**
23
+ * Add an item to the back of the queue.
24
+ * @param {T} data The item to add
25
+ */
26
+ enqueue: (data: T) => void;
27
+ /**
28
+ * Look at the item at the front of the queue, without removing it.
29
+ * @return {T|null} The item, or null when the queue is empty
30
+ */
31
+ peek: () => T | null;
32
+ /**
33
+ * Count the items in the queue.
34
+ * @return {number}
35
+ */
36
+ size: () => number;
37
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file Stack recipe.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ * @memberOf module:collect-your-stuff
6
+ */
7
+ /**
8
+ * Define a last-in-first-out stack: items are added to the top (push) and taken from the top (pop).
9
+ */
10
+ export interface IsStack<T = any> {
11
+ /**
12
+ * Check whether the stack has no items.
13
+ * @return {boolean}
14
+ */
15
+ empty: () => boolean;
16
+ /**
17
+ * Look at the item on the top of the stack, without removing it.
18
+ * @return {T|null} The item, or null when the stack is empty
19
+ */
20
+ peek: () => T | null;
21
+ /**
22
+ * Take the item from the top of the stack.
23
+ * @return {T|null} The item, or null when the stack is empty
24
+ */
25
+ pop: () => T | null;
26
+ /**
27
+ * Add an item to the top of the stack.
28
+ * @param {T} data The item to add
29
+ */
30
+ push: (data: T) => void;
31
+ /**
32
+ * Count the items in the stack.
33
+ * @return {number}
34
+ */
35
+ size: () => number;
36
+ }