effect 2.0.2 → 2.0.4

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 (127) hide show
  1. package/Cron/package.json +6 -0
  2. package/FiberMap/package.json +6 -0
  3. package/FiberSet/package.json +6 -0
  4. package/Trie/package.json +6 -0
  5. package/dist/cjs/Cron.js +457 -0
  6. package/dist/cjs/Cron.js.map +1 -0
  7. package/dist/cjs/Fiber.js.map +1 -1
  8. package/dist/cjs/FiberMap.js +176 -0
  9. package/dist/cjs/FiberMap.js.map +1 -0
  10. package/dist/cjs/FiberSet.js +150 -0
  11. package/dist/cjs/FiberSet.js.map +1 -0
  12. package/dist/cjs/MutableHashMap.js +11 -1
  13. package/dist/cjs/MutableHashMap.js.map +1 -1
  14. package/dist/cjs/MutableHashSet.js +7 -1
  15. package/dist/cjs/MutableHashSet.js.map +1 -1
  16. package/dist/cjs/MutableList.js +8 -11
  17. package/dist/cjs/MutableList.js.map +1 -1
  18. package/dist/cjs/Schedule.js +12 -1
  19. package/dist/cjs/Schedule.js.map +1 -1
  20. package/dist/cjs/Struct.js +16 -1
  21. package/dist/cjs/Struct.js.map +1 -1
  22. package/dist/cjs/Trie.js +680 -0
  23. package/dist/cjs/Trie.js.map +1 -0
  24. package/dist/cjs/index.js +10 -2
  25. package/dist/cjs/index.js.map +1 -1
  26. package/dist/cjs/internal/hashMap/node.js +2 -2
  27. package/dist/cjs/internal/hashMap/node.js.map +1 -1
  28. package/dist/cjs/internal/pubsub.js +11 -17
  29. package/dist/cjs/internal/pubsub.js.map +1 -1
  30. package/dist/cjs/internal/redBlackTree/node.js +35 -30
  31. package/dist/cjs/internal/redBlackTree/node.js.map +1 -1
  32. package/dist/cjs/internal/redBlackTree.js +69 -13
  33. package/dist/cjs/internal/redBlackTree.js.map +1 -1
  34. package/dist/cjs/internal/schedule.js +29 -2
  35. package/dist/cjs/internal/schedule.js.map +1 -1
  36. package/dist/cjs/internal/stack.js +6 -11
  37. package/dist/cjs/internal/stack.js.map +1 -1
  38. package/dist/cjs/internal/trie.js +588 -0
  39. package/dist/cjs/internal/trie.js.map +1 -0
  40. package/dist/cjs/internal/version.js +1 -1
  41. package/dist/dts/Cron.d.ts +170 -0
  42. package/dist/dts/Cron.d.ts.map +1 -0
  43. package/dist/dts/Fiber.d.ts +6 -0
  44. package/dist/dts/Fiber.d.ts.map +1 -1
  45. package/dist/dts/FiberMap.d.ts +125 -0
  46. package/dist/dts/FiberMap.d.ts.map +1 -0
  47. package/dist/dts/FiberSet.d.ts +99 -0
  48. package/dist/dts/FiberSet.d.ts.map +1 -0
  49. package/dist/dts/MutableHashMap.d.ts +4 -0
  50. package/dist/dts/MutableHashMap.d.ts.map +1 -1
  51. package/dist/dts/MutableHashSet.d.ts +5 -0
  52. package/dist/dts/MutableHashSet.d.ts.map +1 -1
  53. package/dist/dts/MutableList.d.ts.map +1 -1
  54. package/dist/dts/Schedule.d.ts +12 -0
  55. package/dist/dts/Schedule.d.ts.map +1 -1
  56. package/dist/dts/Struct.d.ts +17 -3
  57. package/dist/dts/Struct.d.ts.map +1 -1
  58. package/dist/dts/Trie.d.ts +740 -0
  59. package/dist/dts/Trie.d.ts.map +1 -0
  60. package/dist/dts/Types.d.ts +4 -0
  61. package/dist/dts/Types.d.ts.map +1 -1
  62. package/dist/dts/index.d.ts +30 -0
  63. package/dist/dts/index.d.ts.map +1 -1
  64. package/dist/dts/internal/redBlackTree/node.d.ts +8 -0
  65. package/dist/dts/internal/redBlackTree/node.d.ts.map +1 -1
  66. package/dist/dts/internal/stack.d.ts +1 -1
  67. package/dist/dts/internal/stack.d.ts.map +1 -1
  68. package/dist/dts/internal/trie.d.ts +2 -0
  69. package/dist/dts/internal/trie.d.ts.map +1 -0
  70. package/dist/dts/internal/version.d.ts +1 -1
  71. package/dist/esm/Cron.js +418 -0
  72. package/dist/esm/Cron.js.map +1 -0
  73. package/dist/esm/Fiber.js.map +1 -1
  74. package/dist/esm/FiberMap.js +140 -0
  75. package/dist/esm/FiberMap.js.map +1 -0
  76. package/dist/esm/FiberSet.js +114 -0
  77. package/dist/esm/FiberSet.js.map +1 -0
  78. package/dist/esm/MutableHashMap.js +9 -0
  79. package/dist/esm/MutableHashMap.js.map +1 -1
  80. package/dist/esm/MutableHashSet.js +5 -0
  81. package/dist/esm/MutableHashSet.js.map +1 -1
  82. package/dist/esm/MutableList.js +8 -11
  83. package/dist/esm/MutableList.js.map +1 -1
  84. package/dist/esm/Schedule.js +11 -0
  85. package/dist/esm/Schedule.js.map +1 -1
  86. package/dist/esm/Struct.js +14 -0
  87. package/dist/esm/Struct.js.map +1 -1
  88. package/dist/esm/Trie.js +648 -0
  89. package/dist/esm/Trie.js.map +1 -0
  90. package/dist/esm/index.js +30 -0
  91. package/dist/esm/index.js.map +1 -1
  92. package/dist/esm/internal/hashMap/node.js +2 -2
  93. package/dist/esm/internal/hashMap/node.js.map +1 -1
  94. package/dist/esm/internal/pubsub.js +11 -17
  95. package/dist/esm/internal/pubsub.js.map +1 -1
  96. package/dist/esm/internal/redBlackTree/node.js +31 -25
  97. package/dist/esm/internal/redBlackTree/node.js.map +1 -1
  98. package/dist/esm/internal/redBlackTree.js +69 -13
  99. package/dist/esm/internal/redBlackTree.js.map +1 -1
  100. package/dist/esm/internal/schedule.js +26 -0
  101. package/dist/esm/internal/schedule.js.map +1 -1
  102. package/dist/esm/internal/stack.js +4 -9
  103. package/dist/esm/internal/stack.js.map +1 -1
  104. package/dist/esm/internal/trie.js +547 -0
  105. package/dist/esm/internal/trie.js.map +1 -0
  106. package/dist/esm/internal/version.js +1 -1
  107. package/package.json +33 -1
  108. package/src/Cron.ts +525 -0
  109. package/src/Fiber.ts +7 -0
  110. package/src/FiberMap.ts +269 -0
  111. package/src/FiberSet.ts +194 -0
  112. package/src/MutableHashMap.ts +10 -0
  113. package/src/MutableHashSet.ts +6 -0
  114. package/src/MutableList.ts +15 -7
  115. package/src/Schedule.ts +13 -0
  116. package/src/Struct.ts +24 -6
  117. package/src/Trie.ts +772 -0
  118. package/src/Types.ts +5 -0
  119. package/src/index.ts +34 -0
  120. package/src/internal/hashMap/node.ts +3 -3
  121. package/src/internal/pubsub.ts +15 -14
  122. package/src/internal/redBlackTree/node.ts +37 -17
  123. package/src/internal/redBlackTree.ts +73 -38
  124. package/src/internal/schedule.ts +42 -0
  125. package/src/internal/stack.ts +8 -2
  126. package/src/internal/trie.ts +721 -0
  127. package/src/internal/version.ts +1 -1
package/src/Types.ts CHANGED
@@ -174,3 +174,8 @@ export type Covariant<A> = (_: never) => A
174
174
  * @category models
175
175
  */
176
176
  export type Contravariant<A> = (_: A) => void
177
+
178
+ /**
179
+ * @since 2.0.0
180
+ */
181
+ export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
package/src/index.ts CHANGED
@@ -170,6 +170,11 @@ export * as Console from "./Console.js"
170
170
  */
171
171
  export * as Context from "./Context.js"
172
172
 
173
+ /**
174
+ * @since 2.0.0
175
+ */
176
+ export * as Cron from "./Cron.js"
177
+
173
178
  /**
174
179
  * @since 2.0.0
175
180
  */
@@ -255,6 +260,11 @@ export * as Fiber from "./Fiber.js"
255
260
  */
256
261
  export * as FiberId from "./FiberId.js"
257
262
 
263
+ /**
264
+ * @since 2.0.0
265
+ */
266
+ export * as FiberMap from "./FiberMap.js"
267
+
258
268
  /**
259
269
  * @since 2.0.0
260
270
  */
@@ -270,6 +280,11 @@ export * as FiberRefs from "./FiberRefs.js"
270
280
  */
271
281
  export * as FiberRefsPatch from "./FiberRefsPatch.js"
272
282
 
283
+ /**
284
+ * @since 2.0.0
285
+ */
286
+ export * as FiberSet from "./FiberSet.js"
287
+
273
288
  /**
274
289
  * @since 2.0.0
275
290
  */
@@ -832,6 +847,25 @@ export * as TestSized from "./TestSized.js"
832
847
  */
833
848
  export * as Tracer from "./Tracer.js"
834
849
 
850
+ /**
851
+ * A `Trie` is used for locating specific `string` keys from within a set.
852
+ *
853
+ * It works similar to `HashMap`, but with keys required to be `string`.
854
+ * This constraint unlocks some performance optimizations and new methods to get string prefixes (e.g. `keysWithPrefix`, `longestPrefixOf`).
855
+ *
856
+ * Prefix search is also the main feature that makes a `Trie` more suited than `HashMap` for certain usecases.
857
+ *
858
+ * A `Trie` is often used to store a dictionary (list of words) that can be searched
859
+ * in a manner that allows for efficient generation of completion lists
860
+ * (e.g. predict the rest of a word a user is typing).
861
+ *
862
+ * A `Trie` has O(n) lookup time where `n` is the size of the key,
863
+ * or even less than `n` on search misses.
864
+ *
865
+ * @since 2.0.0
866
+ */
867
+ export * as Trie from "./Trie.js"
868
+
835
869
  /**
836
870
  * This module provides utility functions for working with tuples in TypeScript.
837
871
  *
@@ -2,7 +2,7 @@ import { equals } from "../../Equal.js"
2
2
  import type { HashMap } from "../../HashMap.js"
3
3
  import * as O from "../../Option.js"
4
4
  import { isTagged } from "../../Predicate.js"
5
- import { Stack } from "../stack.js"
5
+ import * as Stack from "../stack.js"
6
6
  import { arraySpliceIn, arraySpliceOut, arrayUpdate } from "./array.js"
7
7
  import { fromBitmap, hashFragment, toBitmap } from "./bitwise.js"
8
8
  import { MAX_INDEX_NODE, MIN_ARRAY_NODE, SIZE } from "./config.js"
@@ -370,14 +370,14 @@ function mergeLeaves<K, V>(
370
370
  h2: number,
371
371
  n2: Node<K, V>
372
372
  ): Node<K, V> {
373
- let stack: Stack<(node: Node<K, V>) => Node<K, V>> | undefined = undefined
373
+ let stack: Stack.Stack<(node: Node<K, V>) => Node<K, V>> | undefined = undefined
374
374
  let currentShift = shift
375
375
  // eslint-disable-next-line no-constant-condition
376
376
  while (true) {
377
377
  const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2)
378
378
 
379
379
  if (typeof res === "function") {
380
- stack = new Stack(res, stack)
380
+ stack = Stack.make(res, stack)
381
381
  currentShift = currentShift + SIZE
382
382
  } else {
383
383
  let final = res
@@ -645,28 +645,25 @@ class BoundedPubSubSingleSubscription<in out A> implements Subscription<A> {
645
645
  }
646
646
 
647
647
  /** @internal */
648
- class Node<out A> {
649
- constructor(
650
- public value: A | AbsentValue,
651
- public subscribers: number,
652
- public next: Node<A> | null
653
- ) {
654
- }
648
+ interface Node<out A> {
649
+ value: A | AbsentValue
650
+ subscribers: number
651
+ next: Node<A> | null
655
652
  }
656
653
 
657
654
  /** @internal */
658
655
  class UnboundedPubSub<in out A> implements AtomicPubSub<A> {
659
- publisherHead = new Node<A>(AbsentValue, 0, null)
656
+ publisherHead: Node<A> = {
657
+ value: AbsentValue,
658
+ subscribers: 0,
659
+ next: null
660
+ }
661
+ publisherTail = this.publisherHead
660
662
  publisherIndex = 0
661
- publisherTail: Node<A>
662
663
  subscribersIndex = 0
663
664
 
664
665
  readonly capacity = Number.MAX_SAFE_INTEGER
665
666
 
666
- constructor() {
667
- this.publisherTail = this.publisherHead
668
- }
669
-
670
667
  isEmpty(): boolean {
671
668
  return this.publisherHead === this.publisherTail
672
669
  }
@@ -682,7 +679,11 @@ class UnboundedPubSub<in out A> implements AtomicPubSub<A> {
682
679
  publish(value: A): boolean {
683
680
  const subscribers = this.publisherTail.subscribers
684
681
  if (subscribers !== 0) {
685
- this.publisherTail.next = new Node(value, subscribers, null)
682
+ this.publisherTail.next = {
683
+ value,
684
+ subscribers,
685
+ next: null
686
+ }
686
687
  this.publisherTail = this.publisherTail.next
687
688
  this.publisherIndex += 1
688
689
  }
@@ -10,22 +10,31 @@ export declare namespace Node {
10
10
  }
11
11
  }
12
12
 
13
- /** @internal */
14
- export class Node<out K, out V> {
15
- constructor(
16
- public color: Node.Color,
17
- public key: K,
18
- public value: V,
19
- public left: Node<K, V> | undefined,
20
- public right: Node<K, V> | undefined,
21
- public count: number
22
- ) {}
13
+ export interface Node<out K, out V> {
14
+ color: Node.Color
15
+ key: K
16
+ value: V
17
+ left: Node<K, V> | undefined
18
+ right: Node<K, V> | undefined
19
+ count: number
23
20
  }
24
21
 
25
22
  /** @internal */
26
- export function clone<K, V>(node: Node<K, V>) {
27
- return new Node(node.color, node.key, node.value, node.left, node.right, node.count)
28
- }
23
+ export const clone = <K, V>({
24
+ color,
25
+ count,
26
+ key,
27
+ left,
28
+ right,
29
+ value
30
+ }: Node<K, V>) => ({
31
+ color,
32
+ key,
33
+ value,
34
+ left,
35
+ right,
36
+ count
37
+ })
29
38
 
30
39
  /** @internal */
31
40
  export function swap<K, V>(n: Node<K, V>, v: Node<K, V>) {
@@ -38,11 +47,22 @@ export function swap<K, V>(n: Node<K, V>, v: Node<K, V>) {
38
47
  }
39
48
 
40
49
  /** @internal */
41
- export function repaint<K, V>(node: Node<K, V>, color: Node.Color) {
42
- return new Node(color, node.key, node.value, node.left, node.right, node.count)
43
- }
50
+ export const repaint = <K, V>({
51
+ count,
52
+ key,
53
+ left,
54
+ right,
55
+ value
56
+ }: Node<K, V>, color: Node.Color) => ({
57
+ color,
58
+ key,
59
+ value,
60
+ left,
61
+ right,
62
+ count
63
+ })
44
64
 
45
65
  /** @internal */
46
- export function recount<K, V>(node: Node<K, V>) {
66
+ export const recount = <K, V>(node: Node<K, V>) => {
47
67
  node.count = 1 + (node.left?.count ?? 0) + (node.right?.count ?? 0)
48
68
  }
@@ -11,7 +11,7 @@ import { hasProperty } from "../Predicate.js"
11
11
  import type * as RBT from "../RedBlackTree.js"
12
12
  import { Direction, RedBlackTreeIterator } from "./redBlackTree/iterator.js"
13
13
  import * as Node from "./redBlackTree/node.js"
14
- import { Stack } from "./stack.js"
14
+ import * as Stack from "./stack.js"
15
15
 
16
16
  const RedBlackTreeSymbolKey = "effect/RedBlackTree"
17
17
 
@@ -288,27 +288,34 @@ export const insert = dual<
288
288
  }
289
289
  }
290
290
  // Rebuild path to leaf node
291
- n_stack.push(new Node.Node(Node.Color.Red, key, value, undefined, undefined, 1))
291
+ n_stack.push({
292
+ color: Node.Color.Red,
293
+ key,
294
+ value,
295
+ left: undefined,
296
+ right: undefined,
297
+ count: 1
298
+ })
292
299
  for (let s = n_stack.length - 2; s >= 0; --s) {
293
300
  const n2 = n_stack[s]!
294
301
  if (d_stack[s]! <= 0) {
295
- n_stack[s] = new Node.Node(
296
- n2.color,
297
- n2.key,
298
- n2.value,
299
- n_stack[s + 1],
300
- n2.right,
301
- n2.count + 1
302
- )
302
+ n_stack[s] = {
303
+ color: n2.color,
304
+ key: n2.key,
305
+ value: n2.value,
306
+ left: n_stack[s + 1],
307
+ right: n2.right,
308
+ count: n2.count + 1
309
+ }
303
310
  } else {
304
- n_stack[s] = new Node.Node(
305
- n2.color,
306
- n2.key,
307
- n2.value,
308
- n2.left,
309
- n_stack[s + 1],
310
- n2.count + 1
311
- )
311
+ n_stack[s] = {
312
+ color: n2.color,
313
+ key: n2.key,
314
+ value: n2.value,
315
+ left: n2.left,
316
+ right: n_stack[s + 1],
317
+ count: n2.count + 1
318
+ }
312
319
  }
313
320
  }
314
321
  // Rebalance tree using rotations
@@ -778,20 +785,34 @@ export const removeFirst = dual<
778
785
  }
779
786
  const cstack = new Array<Node.Node<K, V>>(stack.length)
780
787
  let n = stack[stack.length - 1]!
781
- cstack[cstack.length - 1] = new Node.Node(
782
- n.color,
783
- n.key,
784
- n.value,
785
- n.left,
786
- n.right,
787
- n.count
788
- )
788
+ cstack[cstack.length - 1] = {
789
+ color: n.color,
790
+ key: n.key,
791
+ value: n.value,
792
+ left: n.left,
793
+ right: n.right,
794
+ count: n.count
795
+ }
789
796
  for (let i = stack.length - 2; i >= 0; --i) {
790
797
  n = stack[i]!
791
798
  if (n.left === stack[i + 1]) {
792
- cstack[i] = new Node.Node(n.color, n.key, n.value, cstack[i + 1], n.right, n.count)
799
+ cstack[i] = {
800
+ color: n.color,
801
+ key: n.key,
802
+ value: n.value,
803
+ left: cstack[i + 1],
804
+ right: n.right,
805
+ count: n.count
806
+ }
793
807
  } else {
794
- cstack[i] = new Node.Node(n.color, n.key, n.value, n.left, cstack[i + 1], n.count)
808
+ cstack[i] = {
809
+ color: n.color,
810
+ key: n.key,
811
+ value: n.value,
812
+ left: n.left,
813
+ right: cstack[i + 1],
814
+ count: n.count
815
+ }
795
816
  }
796
817
  }
797
818
  // Get node
@@ -807,13 +828,27 @@ export const removeFirst = dual<
807
828
  }
808
829
  // Copy path to leaf
809
830
  const v = cstack[split - 1]
810
- cstack.push(new Node.Node(n.color, v!.key, v!.value, n.left, n.right, n.count))
831
+ cstack.push({
832
+ color: n.color,
833
+ key: v!.key,
834
+ value: v!.value,
835
+ left: n.left,
836
+ right: n.right,
837
+ count: n.count
838
+ })
811
839
  cstack[split - 1]!.key = n.key
812
840
  cstack[split - 1]!.value = n.value
813
841
  // Fix up stack
814
842
  for (let i = cstack.length - 2; i >= split; --i) {
815
843
  n = cstack[i]!
816
- cstack[i] = new Node.Node(n.color, n.key, n.value, n.left, cstack[i + 1], n.count)
844
+ cstack[i] = {
845
+ color: n.color,
846
+ key: n.key,
847
+ value: n.value,
848
+ left: n.left,
849
+ right: cstack[i + 1],
850
+ count: n.count
851
+ }
817
852
  }
818
853
  cstack[split - 1]!.left = cstack[split]
819
854
  }
@@ -913,11 +948,11 @@ const visitFull = <K, V, A>(
913
948
  visit: (key: K, value: V) => Option.Option<A>
914
949
  ): Option.Option<A> => {
915
950
  let current: Node.Node<K, V> | undefined = node
916
- let stack: Stack<Node.Node<K, V>> | undefined = undefined
951
+ let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined
917
952
  let done = false
918
953
  while (!done) {
919
954
  if (current != null) {
920
- stack = new Stack(current, stack)
955
+ stack = Stack.make(current, stack)
921
956
  current = current.left
922
957
  } else if (stack != null) {
923
958
  const value = visit(stack.value.key, stack.value.value)
@@ -940,11 +975,11 @@ const visitGreaterThanEqual = <K, V, A>(
940
975
  visit: (key: K, value: V) => Option.Option<A>
941
976
  ): Option.Option<A> => {
942
977
  let current: Node.Node<K, V> | undefined = node
943
- let stack: Stack<Node.Node<K, V>> | undefined = undefined
978
+ let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined
944
979
  let done = false
945
980
  while (!done) {
946
981
  if (current !== undefined) {
947
- stack = new Stack(current, stack)
982
+ stack = Stack.make(current, stack)
948
983
  if (ord(min, current.key) <= 0) {
949
984
  current = current.left
950
985
  } else {
@@ -973,11 +1008,11 @@ const visitLessThan = <K, V, A>(
973
1008
  visit: (key: K, value: V) => Option.Option<A>
974
1009
  ): Option.Option<A> => {
975
1010
  let current: Node.Node<K, V> | undefined = node
976
- let stack: Stack<Node.Node<K, V>> | undefined = undefined
1011
+ let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined
977
1012
  let done = false
978
1013
  while (!done) {
979
1014
  if (current !== undefined) {
980
- stack = new Stack(current, stack)
1015
+ stack = Stack.make(current, stack)
981
1016
  current = current.left
982
1017
  } else if (stack !== undefined && ord(max, stack.value.key) > 0) {
983
1018
  const value = visit(stack.value.key, stack.value.value)
@@ -1001,11 +1036,11 @@ const visitBetween = <K, V, A>(
1001
1036
  visit: (key: K, value: V) => Option.Option<A>
1002
1037
  ): Option.Option<A> => {
1003
1038
  let current: Node.Node<K, V> | undefined = node
1004
- let stack: Stack<Node.Node<K, V>> | undefined = undefined
1039
+ let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined
1005
1040
  let done = false
1006
1041
  while (!done) {
1007
1042
  if (current !== undefined) {
1008
- stack = new Stack(current, stack)
1043
+ stack = Stack.make(current, stack)
1009
1044
  if (ord(min, current.key) <= 0) {
1010
1045
  current = current.left
1011
1046
  } else {
@@ -2,6 +2,7 @@ import type * as Cause from "../Cause.js"
2
2
  import * as Chunk from "../Chunk.js"
3
3
  import * as Clock from "../Clock.js"
4
4
  import * as Context from "../Context.js"
5
+ import * as Cron from "../Cron.js"
5
6
  import * as Duration from "../Duration.js"
6
7
  import type * as Effect from "../Effect.js"
7
8
  import * as Either from "../Either.js"
@@ -419,6 +420,47 @@ export const mapInputEffect = dual<
419
420
  (input) => self.step(now, input, state)
420
421
  )))
421
422
 
423
+ /** @internal */
424
+ export const cron = (expression: string | Cron.Cron): Schedule.Schedule<never, unknown, [number, number]> => {
425
+ const parsed = Cron.isCron(expression) ? Either.right(expression) : Cron.parse(expression)
426
+ return makeWithState<[boolean, [number, number, number]], never, unknown, [number, number]>(
427
+ [true, [Number.MIN_SAFE_INTEGER, 0, 0]],
428
+ (now, _, [initial, previous]) => {
429
+ if (now < previous[0]) {
430
+ return core.succeed([
431
+ [false, previous],
432
+ [previous[1], previous[2]],
433
+ ScheduleDecision.continueWith(Interval.make(previous[1], previous[2]))
434
+ ])
435
+ }
436
+
437
+ if (Either.isLeft(parsed)) {
438
+ return core.die(parsed.left)
439
+ }
440
+
441
+ const cron = parsed.right
442
+ const date = new Date(now)
443
+
444
+ let next: number
445
+ if (initial && Cron.match(cron, date)) {
446
+ next = now
447
+ } else {
448
+ const result = Cron.next(cron, date)
449
+ next = result.getTime()
450
+ }
451
+
452
+ const start = beginningOfMinute(next)
453
+ const end = endOfMinute(next)
454
+ const interval = Interval.make(start, end)
455
+ return core.succeed([
456
+ [false, [next, start, end]],
457
+ [start, end],
458
+ ScheduleDecision.continueWith(interval)
459
+ ])
460
+ }
461
+ )
462
+ }
463
+
422
464
  /** @internal */
423
465
  export const dayOfMonth = (day: number): Schedule.Schedule<never, unknown, number> => {
424
466
  return makeWithState<[number, number], never, unknown, number>(
@@ -1,4 +1,10 @@
1
1
  /** @internal */
2
- export class Stack<out A> {
3
- constructor(readonly value: A, readonly previous?: Stack<A>) {}
2
+ export interface Stack<out A> {
3
+ readonly value: A
4
+ readonly previous: Stack<A> | undefined
4
5
  }
6
+
7
+ export const make = <A>(value: A, previous?: Stack<A>): Stack<A> => ({
8
+ value,
9
+ previous
10
+ })