effect 4.0.0-beta.17 → 4.0.0-beta.19
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/dist/Array.d.ts +127 -299
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +102 -62
- package/dist/Array.js.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +5 -4
- package/dist/Cache.js.map +1 -1
- package/dist/Channel.d.ts +97 -11
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +72 -29
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +54 -247
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +36 -67
- package/dist/Chunk.js.map +1 -1
- package/dist/Effect.d.ts +337 -437
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +118 -134
- package/dist/Effect.js.map +1 -1
- package/dist/Filter.d.ts +0 -33
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +0 -13
- package/dist/Filter.js.map +1 -1
- package/dist/HashMap.d.ts +15 -14
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +4 -4
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +40 -39
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +94 -22
- package/dist/Iterable.js.map +1 -1
- package/dist/Option.d.ts +22 -15
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +14 -7
- package/dist/Option.js.map +1 -1
- package/dist/Pull.d.ts.map +1 -1
- package/dist/Pull.js +1 -1
- package/dist/Pull.js.map +1 -1
- package/dist/Record.d.ts +24 -120
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +21 -41
- package/dist/Record.js.map +1 -1
- package/dist/Sink.d.ts +11 -11
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +53 -6
- package/dist/Sink.js.map +1 -1
- package/dist/Stream.d.ts +198 -386
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +103 -59
- package/dist/Stream.js.map +1 -1
- package/dist/Trie.d.ts +18 -17
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +5 -5
- package/dist/Trie.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +196 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +84 -83
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +24 -24
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +14 -14
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +415 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +7 -7
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +99 -42
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +3 -2
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/trie.js +5 -4
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +0 -9
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +1 -1
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +4 -4
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Sharding.js +1 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/encoding/Sse.js +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +1 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +3 -3
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +190 -342
- package/src/Cache.ts +6 -5
- package/src/Channel.ts +506 -102
- package/src/Chunk.ts +81 -268
- package/src/Effect.ts +437 -518
- package/src/Filter.ts +0 -57
- package/src/HashMap.ts +15 -14
- package/src/Iterable.ts +105 -50
- package/src/Option.ts +30 -20
- package/src/Pull.ts +1 -1
- package/src/Record.ts +43 -152
- package/src/Sink.ts +75 -23
- package/src/Stream.ts +442 -502
- package/src/Trie.ts +18 -17
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +332 -285
- package/src/TxHashSet.ts +111 -116
- package/src/TxPriorityQueue.ts +767 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +29 -32
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/index.ts +45 -0
- package/src/internal/effect.ts +368 -163
- package/src/internal/hashMap.ts +7 -5
- package/src/internal/trie.ts +16 -9
- package/src/unstable/ai/Tool.ts +0 -9
- package/src/unstable/cli/Command.ts +6 -4
- package/src/unstable/cluster/K8sHttpClient.ts +4 -4
- package/src/unstable/cluster/Sharding.ts +1 -1
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/rpc/RpcServer.ts +1 -7
- package/src/unstable/socket/Socket.ts +9 -11
package/src/Chunk.ts
CHANGED
|
@@ -72,6 +72,7 @@ import * as RA from "./Array.ts"
|
|
|
72
72
|
import type { NonEmptyReadonlyArray } from "./Array.ts"
|
|
73
73
|
import * as Equal from "./Equal.ts"
|
|
74
74
|
import * as Equivalence from "./Equivalence.ts"
|
|
75
|
+
import type * as Filter from "./Filter.ts"
|
|
75
76
|
import { format } from "./Formatter.ts"
|
|
76
77
|
import { dual, identity, pipe } from "./Function.ts"
|
|
77
78
|
import * as Hash from "./Hash.ts"
|
|
@@ -84,6 +85,7 @@ import * as Order from "./Order.ts"
|
|
|
84
85
|
import type { Pipeable } from "./Pipeable.ts"
|
|
85
86
|
import { pipeArguments } from "./Pipeable.ts"
|
|
86
87
|
import { hasProperty, type Predicate, type Refinement } from "./Predicate.ts"
|
|
88
|
+
import * as R from "./Result.ts"
|
|
87
89
|
import type { Result } from "./Result.ts"
|
|
88
90
|
import type { Covariant, NoInfer } from "./Types.ts"
|
|
89
91
|
import * as UndefinedOr from "./UndefinedOr.ts"
|
|
@@ -1515,19 +1517,19 @@ export const appendAll: {
|
|
|
1515
1517
|
* @example
|
|
1516
1518
|
* ```ts
|
|
1517
1519
|
* import { Chunk } from "effect"
|
|
1518
|
-
* import * as
|
|
1520
|
+
* import * as Result from "effect/Result"
|
|
1519
1521
|
*
|
|
1520
1522
|
* const chunk = Chunk.make("1", "2", "hello", "3", "world")
|
|
1521
1523
|
* const numbers = Chunk.filterMap(chunk, (str) => {
|
|
1522
1524
|
* const num = parseInt(str)
|
|
1523
|
-
* return isNaN(num) ?
|
|
1525
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1524
1526
|
* })
|
|
1525
1527
|
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
1526
1528
|
*
|
|
1527
1529
|
* // With index parameter
|
|
1528
1530
|
* const evenIndexNumbers = Chunk.filterMap(chunk, (str, i) => {
|
|
1529
1531
|
* const num = parseInt(str)
|
|
1530
|
-
* return isNaN(num) || i % 2 !== 0 ?
|
|
1532
|
+
* return isNaN(num) || i % 2 !== 0 ? Result.failVoid : Result.succeed(num)
|
|
1531
1533
|
* })
|
|
1532
1534
|
* console.log(Chunk.toArray(evenIndexNumbers)) // [1]
|
|
1533
1535
|
* ```
|
|
@@ -1542,19 +1544,19 @@ export const filterMap: {
|
|
|
1542
1544
|
* @example
|
|
1543
1545
|
* ```ts
|
|
1544
1546
|
* import { Chunk } from "effect"
|
|
1545
|
-
* import * as
|
|
1547
|
+
* import * as Result from "effect/Result"
|
|
1546
1548
|
*
|
|
1547
1549
|
* const chunk = Chunk.make("1", "2", "hello", "3", "world")
|
|
1548
1550
|
* const numbers = Chunk.filterMap(chunk, (str) => {
|
|
1549
1551
|
* const num = parseInt(str)
|
|
1550
|
-
* return isNaN(num) ?
|
|
1552
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1551
1553
|
* })
|
|
1552
1554
|
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
1553
1555
|
*
|
|
1554
1556
|
* // With index parameter
|
|
1555
1557
|
* const evenIndexNumbers = Chunk.filterMap(chunk, (str, i) => {
|
|
1556
1558
|
* const num = parseInt(str)
|
|
1557
|
-
* return isNaN(num) || i % 2 !== 0 ?
|
|
1559
|
+
* return isNaN(num) || i % 2 !== 0 ? Result.failVoid : Result.succeed(num)
|
|
1558
1560
|
* })
|
|
1559
1561
|
* console.log(Chunk.toArray(evenIndexNumbers)) // [1]
|
|
1560
1562
|
* ```
|
|
@@ -1562,26 +1564,26 @@ export const filterMap: {
|
|
|
1562
1564
|
* @since 2.0.0
|
|
1563
1565
|
* @category filtering
|
|
1564
1566
|
*/
|
|
1565
|
-
<A, B>(f:
|
|
1567
|
+
<A, B, X>(f: Filter.Filter<A, B, X, [i: number]>): (self: Chunk<A>) => Chunk<B>
|
|
1566
1568
|
/**
|
|
1567
1569
|
* Returns a filtered and mapped subset of the elements.
|
|
1568
1570
|
*
|
|
1569
1571
|
* @example
|
|
1570
1572
|
* ```ts
|
|
1571
1573
|
* import { Chunk } from "effect"
|
|
1572
|
-
* import * as
|
|
1574
|
+
* import * as Result from "effect/Result"
|
|
1573
1575
|
*
|
|
1574
1576
|
* const chunk = Chunk.make("1", "2", "hello", "3", "world")
|
|
1575
1577
|
* const numbers = Chunk.filterMap(chunk, (str) => {
|
|
1576
1578
|
* const num = parseInt(str)
|
|
1577
|
-
* return isNaN(num) ?
|
|
1579
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1578
1580
|
* })
|
|
1579
1581
|
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
1580
1582
|
*
|
|
1581
1583
|
* // With index parameter
|
|
1582
1584
|
* const evenIndexNumbers = Chunk.filterMap(chunk, (str, i) => {
|
|
1583
1585
|
* const num = parseInt(str)
|
|
1584
|
-
* return isNaN(num) || i % 2 !== 0 ?
|
|
1586
|
+
* return isNaN(num) || i % 2 !== 0 ? Result.failVoid : Result.succeed(num)
|
|
1585
1587
|
* })
|
|
1586
1588
|
* console.log(Chunk.toArray(evenIndexNumbers)) // [1]
|
|
1587
1589
|
* ```
|
|
@@ -1589,16 +1591,16 @@ export const filterMap: {
|
|
|
1589
1591
|
* @since 2.0.0
|
|
1590
1592
|
* @category filtering
|
|
1591
1593
|
*/
|
|
1592
|
-
<A, B>(self: Chunk<A>, f:
|
|
1594
|
+
<A, B, X>(self: Chunk<A>, f: Filter.Filter<A, B, X, [i: number]>): Chunk<B>
|
|
1593
1595
|
} = dual(
|
|
1594
1596
|
2,
|
|
1595
|
-
<A, B>(self: Chunk<A>, f:
|
|
1597
|
+
<A, B, X>(self: Chunk<A>, f: Filter.Filter<A, B, X, [i: number]>): Chunk<B> => {
|
|
1596
1598
|
const as = RA.fromIterable(self)
|
|
1597
1599
|
const out: Array<B> = []
|
|
1598
1600
|
for (let i = 0; i < as.length; i++) {
|
|
1599
|
-
const
|
|
1600
|
-
if (
|
|
1601
|
-
out.push(
|
|
1601
|
+
const result = f(as[i], i)
|
|
1602
|
+
if (R.isSuccess(result)) {
|
|
1603
|
+
out.push(result.success)
|
|
1602
1604
|
}
|
|
1603
1605
|
}
|
|
1604
1606
|
return fromArrayUnsafe(out)
|
|
@@ -1716,17 +1718,17 @@ export const filter: {
|
|
|
1716
1718
|
)
|
|
1717
1719
|
|
|
1718
1720
|
/**
|
|
1719
|
-
* Transforms all elements of the chunk for as long as the specified function
|
|
1721
|
+
* Transforms all elements of the chunk for as long as the specified function succeeds.
|
|
1720
1722
|
*
|
|
1721
1723
|
* @example
|
|
1722
1724
|
* ```ts
|
|
1723
1725
|
* import { Chunk } from "effect"
|
|
1724
|
-
* import * as
|
|
1726
|
+
* import * as Result from "effect/Result"
|
|
1725
1727
|
*
|
|
1726
1728
|
* const chunk = Chunk.make("1", "2", "hello", "3", "4")
|
|
1727
1729
|
* const result = Chunk.filterMapWhile(chunk, (s) => {
|
|
1728
1730
|
* const num = parseInt(s)
|
|
1729
|
-
* return isNaN(num) ?
|
|
1731
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1730
1732
|
* })
|
|
1731
1733
|
* console.log(Chunk.toArray(result)) // [1, 2]
|
|
1732
1734
|
* // Stops at "hello" and doesn't process "3", "4"
|
|
@@ -1734,7 +1736,7 @@ export const filter: {
|
|
|
1734
1736
|
* // Compare with regular filterMap
|
|
1735
1737
|
* const allNumbers = Chunk.filterMap(chunk, (s) => {
|
|
1736
1738
|
* const num = parseInt(s)
|
|
1737
|
-
* return isNaN(num) ?
|
|
1739
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1738
1740
|
* })
|
|
1739
1741
|
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4]
|
|
1740
1742
|
* ```
|
|
@@ -1744,17 +1746,17 @@ export const filter: {
|
|
|
1744
1746
|
*/
|
|
1745
1747
|
export const filterMapWhile: {
|
|
1746
1748
|
/**
|
|
1747
|
-
* Transforms all elements of the chunk for as long as the specified function
|
|
1749
|
+
* Transforms all elements of the chunk for as long as the specified function succeeds.
|
|
1748
1750
|
*
|
|
1749
1751
|
* @example
|
|
1750
1752
|
* ```ts
|
|
1751
1753
|
* import { Chunk } from "effect"
|
|
1752
|
-
* import * as
|
|
1754
|
+
* import * as Result from "effect/Result"
|
|
1753
1755
|
*
|
|
1754
1756
|
* const chunk = Chunk.make("1", "2", "hello", "3", "4")
|
|
1755
1757
|
* const result = Chunk.filterMapWhile(chunk, (s) => {
|
|
1756
1758
|
* const num = parseInt(s)
|
|
1757
|
-
* return isNaN(num) ?
|
|
1759
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1758
1760
|
* })
|
|
1759
1761
|
* console.log(Chunk.toArray(result)) // [1, 2]
|
|
1760
1762
|
* // Stops at "hello" and doesn't process "3", "4"
|
|
@@ -1762,7 +1764,7 @@ export const filterMapWhile: {
|
|
|
1762
1764
|
* // Compare with regular filterMap
|
|
1763
1765
|
* const allNumbers = Chunk.filterMap(chunk, (s) => {
|
|
1764
1766
|
* const num = parseInt(s)
|
|
1765
|
-
* return isNaN(num) ?
|
|
1767
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1766
1768
|
* })
|
|
1767
1769
|
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4]
|
|
1768
1770
|
* ```
|
|
@@ -1770,19 +1772,19 @@ export const filterMapWhile: {
|
|
|
1770
1772
|
* @since 2.0.0
|
|
1771
1773
|
* @category filtering
|
|
1772
1774
|
*/
|
|
1773
|
-
<A, B>(f:
|
|
1775
|
+
<A, B, X>(f: Filter.Filter<A, B, X>): (self: Chunk<A>) => Chunk<B>
|
|
1774
1776
|
/**
|
|
1775
|
-
* Transforms all elements of the chunk for as long as the specified function
|
|
1777
|
+
* Transforms all elements of the chunk for as long as the specified function succeeds.
|
|
1776
1778
|
*
|
|
1777
1779
|
* @example
|
|
1778
1780
|
* ```ts
|
|
1779
1781
|
* import { Chunk } from "effect"
|
|
1780
|
-
* import * as
|
|
1782
|
+
* import * as Result from "effect/Result"
|
|
1781
1783
|
*
|
|
1782
1784
|
* const chunk = Chunk.make("1", "2", "hello", "3", "4")
|
|
1783
1785
|
* const result = Chunk.filterMapWhile(chunk, (s) => {
|
|
1784
1786
|
* const num = parseInt(s)
|
|
1785
|
-
* return isNaN(num) ?
|
|
1787
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1786
1788
|
* })
|
|
1787
1789
|
* console.log(Chunk.toArray(result)) // [1, 2]
|
|
1788
1790
|
* // Stops at "hello" and doesn't process "3", "4"
|
|
@@ -1790,7 +1792,7 @@ export const filterMapWhile: {
|
|
|
1790
1792
|
* // Compare with regular filterMap
|
|
1791
1793
|
* const allNumbers = Chunk.filterMap(chunk, (s) => {
|
|
1792
1794
|
* const num = parseInt(s)
|
|
1793
|
-
* return isNaN(num) ?
|
|
1795
|
+
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
|
|
1794
1796
|
* })
|
|
1795
1797
|
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3, 4]
|
|
1796
1798
|
* ```
|
|
@@ -1798,13 +1800,13 @@ export const filterMapWhile: {
|
|
|
1798
1800
|
* @since 2.0.0
|
|
1799
1801
|
* @category filtering
|
|
1800
1802
|
*/
|
|
1801
|
-
<A, B>(self: Chunk<A>, f:
|
|
1802
|
-
} = dual(2, <A, B>(self: Chunk<A>, f:
|
|
1803
|
+
<A, B, X>(self: Chunk<A>, f: Filter.Filter<A, B, X>): Chunk<B>
|
|
1804
|
+
} = dual(2, <A, B, X>(self: Chunk<A>, f: Filter.Filter<A, B, X>): Chunk<B> => {
|
|
1803
1805
|
const out: Array<B> = []
|
|
1804
1806
|
for (const a of self) {
|
|
1805
|
-
const
|
|
1806
|
-
if (
|
|
1807
|
-
out.push(
|
|
1807
|
+
const result = f(a)
|
|
1808
|
+
if (R.isSuccess(result)) {
|
|
1809
|
+
out.push(result.success)
|
|
1808
1810
|
} else {
|
|
1809
1811
|
break
|
|
1810
1812
|
}
|
|
@@ -1829,7 +1831,15 @@ export const filterMapWhile: {
|
|
|
1829
1831
|
* @category filtering
|
|
1830
1832
|
* @since 2.0.0
|
|
1831
1833
|
*/
|
|
1832
|
-
export const compact = <A>(self: Chunk<Option<A>>): Chunk<A> =>
|
|
1834
|
+
export const compact = <A>(self: Chunk<Option<A>>): Chunk<A> => {
|
|
1835
|
+
const out: Array<A> = []
|
|
1836
|
+
for (const option of self) {
|
|
1837
|
+
if (O.isSome(option)) {
|
|
1838
|
+
out.push(option.value)
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
return fromArrayUnsafe(out)
|
|
1842
|
+
}
|
|
1833
1843
|
|
|
1834
1844
|
/**
|
|
1835
1845
|
* Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.
|
|
@@ -2769,31 +2779,21 @@ export const mapAccum: {
|
|
|
2769
2779
|
})
|
|
2770
2780
|
|
|
2771
2781
|
/**
|
|
2772
|
-
*
|
|
2782
|
+
* Splits a chunk using a `Filter` into failures and successes.
|
|
2783
|
+
*
|
|
2784
|
+
* - Returns `[excluded, satisfying]`.
|
|
2785
|
+
* - The filter receives `(element, index)`.
|
|
2773
2786
|
*
|
|
2774
2787
|
* @example
|
|
2775
2788
|
* ```ts
|
|
2776
|
-
* import { Chunk } from "effect"
|
|
2789
|
+
* import { Chunk, Result } from "effect"
|
|
2777
2790
|
*
|
|
2778
|
-
* const
|
|
2779
|
-
*
|
|
2780
|
-
* console.log(Chunk.toArray(odds)) // [1, 3, 5]
|
|
2781
|
-
* console.log(Chunk.toArray(evens)) // [2, 4, 6]
|
|
2782
|
-
*
|
|
2783
|
-
* // With index parameter
|
|
2784
|
-
* const words = Chunk.make("a", "bb", "ccc", "dddd")
|
|
2785
|
-
* const [short, long] = Chunk.partition(words, (word, i) => word.length > i)
|
|
2786
|
-
* console.log(Chunk.toArray(short)) // ["a", "bb"]
|
|
2787
|
-
* console.log(Chunk.toArray(long)) // ["ccc", "dddd"]
|
|
2788
|
-
*
|
|
2789
|
-
* // With refinement
|
|
2790
|
-
* const mixed = Chunk.make("hello", 42, "world", 100)
|
|
2791
|
-
* const [strings, numbers] = Chunk.partition(
|
|
2792
|
-
* mixed,
|
|
2793
|
-
* (x): x is number => typeof x === "number"
|
|
2791
|
+
* const [excluded, satisfying] = Chunk.partition(Chunk.make(1, -2, 3), (n, i) =>
|
|
2792
|
+
* n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
|
|
2794
2793
|
* )
|
|
2795
|
-
*
|
|
2796
|
-
* console.log(Chunk.toArray(
|
|
2794
|
+
*
|
|
2795
|
+
* console.log(Chunk.toArray(excluded)) // ["negative:-2"]
|
|
2796
|
+
* console.log(Chunk.toArray(satisfying)) // [1, 5]
|
|
2797
2797
|
* ```
|
|
2798
2798
|
*
|
|
2799
2799
|
* @category filtering
|
|
@@ -2801,247 +2801,60 @@ export const mapAccum: {
|
|
|
2801
2801
|
*/
|
|
2802
2802
|
export const partition: {
|
|
2803
2803
|
/**
|
|
2804
|
-
*
|
|
2804
|
+
* Splits a chunk using a `Filter` into failures and successes.
|
|
2805
2805
|
*
|
|
2806
|
-
*
|
|
2807
|
-
*
|
|
2808
|
-
* import { Chunk } from "effect"
|
|
2809
|
-
*
|
|
2810
|
-
* const chunk = Chunk.make(1, 2, 3, 4, 5, 6)
|
|
2811
|
-
* const [odds, evens] = Chunk.partition(chunk, (n) => n % 2 === 0)
|
|
2812
|
-
* console.log(Chunk.toArray(odds)) // [1, 3, 5]
|
|
2813
|
-
* console.log(Chunk.toArray(evens)) // [2, 4, 6]
|
|
2814
|
-
*
|
|
2815
|
-
* // With index parameter
|
|
2816
|
-
* const words = Chunk.make("a", "bb", "ccc", "dddd")
|
|
2817
|
-
* const [short, long] = Chunk.partition(words, (word, i) => word.length > i)
|
|
2818
|
-
* console.log(Chunk.toArray(short)) // ["a", "bb"]
|
|
2819
|
-
* console.log(Chunk.toArray(long)) // ["ccc", "dddd"]
|
|
2820
|
-
*
|
|
2821
|
-
* // With refinement
|
|
2822
|
-
* const mixed = Chunk.make("hello", 42, "world", 100)
|
|
2823
|
-
* const [strings, numbers] = Chunk.partition(
|
|
2824
|
-
* mixed,
|
|
2825
|
-
* (x): x is number => typeof x === "number"
|
|
2826
|
-
* )
|
|
2827
|
-
* console.log(Chunk.toArray(strings)) // ["hello", "world"]
|
|
2828
|
-
* console.log(Chunk.toArray(numbers)) // [42, 100]
|
|
2829
|
-
* ```
|
|
2830
|
-
*
|
|
2831
|
-
* @category filtering
|
|
2832
|
-
* @since 2.0.0
|
|
2833
|
-
*/
|
|
2834
|
-
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Chunk<A>) => [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>]
|
|
2835
|
-
/**
|
|
2836
|
-
* Separate elements based on a predicate that also exposes the index of the element.
|
|
2806
|
+
* - Returns `[excluded, satisfying]`.
|
|
2807
|
+
* - The filter receives `(element, index)`.
|
|
2837
2808
|
*
|
|
2838
2809
|
* @example
|
|
2839
2810
|
* ```ts
|
|
2840
|
-
* import { Chunk } from "effect"
|
|
2811
|
+
* import { Chunk, Result } from "effect"
|
|
2841
2812
|
*
|
|
2842
|
-
* const
|
|
2843
|
-
*
|
|
2844
|
-
* console.log(Chunk.toArray(odds)) // [1, 3, 5]
|
|
2845
|
-
* console.log(Chunk.toArray(evens)) // [2, 4, 6]
|
|
2846
|
-
*
|
|
2847
|
-
* // With index parameter
|
|
2848
|
-
* const words = Chunk.make("a", "bb", "ccc", "dddd")
|
|
2849
|
-
* const [short, long] = Chunk.partition(words, (word, i) => word.length > i)
|
|
2850
|
-
* console.log(Chunk.toArray(short)) // ["a", "bb"]
|
|
2851
|
-
* console.log(Chunk.toArray(long)) // ["ccc", "dddd"]
|
|
2852
|
-
*
|
|
2853
|
-
* // With refinement
|
|
2854
|
-
* const mixed = Chunk.make("hello", 42, "world", 100)
|
|
2855
|
-
* const [strings, numbers] = Chunk.partition(
|
|
2856
|
-
* mixed,
|
|
2857
|
-
* (x): x is number => typeof x === "number"
|
|
2813
|
+
* const [excluded, satisfying] = Chunk.partition(Chunk.make(1, -2, 3), (n, i) =>
|
|
2814
|
+
* n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
|
|
2858
2815
|
* )
|
|
2859
|
-
* console.log(Chunk.toArray(strings)) // ["hello", "world"]
|
|
2860
|
-
* console.log(Chunk.toArray(numbers)) // [42, 100]
|
|
2861
|
-
* ```
|
|
2862
|
-
*
|
|
2863
|
-
* @category filtering
|
|
2864
|
-
* @since 2.0.0
|
|
2865
|
-
*/
|
|
2866
|
-
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Chunk<A>) => [excluded: Chunk<A>, satisfying: Chunk<A>]
|
|
2867
|
-
/**
|
|
2868
|
-
* Separate elements based on a predicate that also exposes the index of the element.
|
|
2869
|
-
*
|
|
2870
|
-
* @example
|
|
2871
|
-
* ```ts
|
|
2872
|
-
* import { Chunk } from "effect"
|
|
2873
2816
|
*
|
|
2874
|
-
*
|
|
2875
|
-
*
|
|
2876
|
-
* console.log(Chunk.toArray(odds)) // [1, 3, 5]
|
|
2877
|
-
* console.log(Chunk.toArray(evens)) // [2, 4, 6]
|
|
2878
|
-
*
|
|
2879
|
-
* // With index parameter
|
|
2880
|
-
* const words = Chunk.make("a", "bb", "ccc", "dddd")
|
|
2881
|
-
* const [short, long] = Chunk.partition(words, (word, i) => word.length > i)
|
|
2882
|
-
* console.log(Chunk.toArray(short)) // ["a", "bb"]
|
|
2883
|
-
* console.log(Chunk.toArray(long)) // ["ccc", "dddd"]
|
|
2884
|
-
*
|
|
2885
|
-
* // With refinement
|
|
2886
|
-
* const mixed = Chunk.make("hello", 42, "world", 100)
|
|
2887
|
-
* const [strings, numbers] = Chunk.partition(
|
|
2888
|
-
* mixed,
|
|
2889
|
-
* (x): x is number => typeof x === "number"
|
|
2890
|
-
* )
|
|
2891
|
-
* console.log(Chunk.toArray(strings)) // ["hello", "world"]
|
|
2892
|
-
* console.log(Chunk.toArray(numbers)) // [42, 100]
|
|
2817
|
+
* console.log(Chunk.toArray(excluded)) // ["negative:-2"]
|
|
2818
|
+
* console.log(Chunk.toArray(satisfying)) // [1, 5]
|
|
2893
2819
|
* ```
|
|
2894
2820
|
*
|
|
2895
2821
|
* @category filtering
|
|
2896
2822
|
* @since 2.0.0
|
|
2897
2823
|
*/
|
|
2898
|
-
<A,
|
|
2824
|
+
<A, Pass, Fail>(f: Filter.Filter<NoInfer<A>, Pass, Fail, [i: number]>): (self: Chunk<A>) => [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]
|
|
2899
2825
|
/**
|
|
2900
|
-
*
|
|
2826
|
+
* Splits a chunk using a `Filter` into failures and successes.
|
|
2827
|
+
*
|
|
2828
|
+
* - Returns `[excluded, satisfying]`.
|
|
2829
|
+
* - The filter receives `(element, index)`.
|
|
2901
2830
|
*
|
|
2902
2831
|
* @example
|
|
2903
2832
|
* ```ts
|
|
2904
|
-
* import { Chunk } from "effect"
|
|
2905
|
-
*
|
|
2906
|
-
* const chunk = Chunk.make(1, 2, 3, 4, 5, 6)
|
|
2907
|
-
* const [odds, evens] = Chunk.partition(chunk, (n) => n % 2 === 0)
|
|
2908
|
-
* console.log(Chunk.toArray(odds)) // [1, 3, 5]
|
|
2909
|
-
* console.log(Chunk.toArray(evens)) // [2, 4, 6]
|
|
2910
|
-
*
|
|
2911
|
-
* // With index parameter
|
|
2912
|
-
* const words = Chunk.make("a", "bb", "ccc", "dddd")
|
|
2913
|
-
* const [short, long] = Chunk.partition(words, (word, i) => word.length > i)
|
|
2914
|
-
* console.log(Chunk.toArray(short)) // ["a", "bb"]
|
|
2915
|
-
* console.log(Chunk.toArray(long)) // ["ccc", "dddd"]
|
|
2833
|
+
* import { Chunk, Result } from "effect"
|
|
2916
2834
|
*
|
|
2917
|
-
*
|
|
2918
|
-
*
|
|
2919
|
-
* const [strings, numbers] = Chunk.partition(
|
|
2920
|
-
* mixed,
|
|
2921
|
-
* (x): x is number => typeof x === "number"
|
|
2835
|
+
* const [excluded, satisfying] = Chunk.partition(Chunk.make(1, -2, 3), (n, i) =>
|
|
2836
|
+
* n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
|
|
2922
2837
|
* )
|
|
2923
|
-
*
|
|
2924
|
-
* console.log(Chunk.toArray(
|
|
2838
|
+
*
|
|
2839
|
+
* console.log(Chunk.toArray(excluded)) // ["negative:-2"]
|
|
2840
|
+
* console.log(Chunk.toArray(satisfying)) // [1, 5]
|
|
2925
2841
|
* ```
|
|
2926
2842
|
*
|
|
2927
2843
|
* @category filtering
|
|
2928
2844
|
* @since 2.0.0
|
|
2929
2845
|
*/
|
|
2930
|
-
<A>(self: Chunk<A>,
|
|
2846
|
+
<A, Pass, Fail>(self: Chunk<A>, f: Filter.Filter<A, Pass, Fail, [i: number]>): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>]
|
|
2931
2847
|
} = dual(
|
|
2932
2848
|
2,
|
|
2933
|
-
<A
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
)
|
|
2849
|
+
<A, Pass, Fail>(
|
|
2850
|
+
self: Chunk<A>,
|
|
2851
|
+
f: Filter.Filter<A, Pass, Fail, [i: number]>
|
|
2852
|
+
): [excluded: Chunk<Fail>, satisfying: Chunk<Pass>] => {
|
|
2853
|
+
const [excluded, satisfying] = RA.partition(self, f)
|
|
2854
|
+
return [fromArrayUnsafe(excluded), fromArrayUnsafe(satisfying)]
|
|
2855
|
+
}
|
|
2938
2856
|
)
|
|
2939
2857
|
|
|
2940
|
-
/**
|
|
2941
|
-
* Partitions the elements of this chunk into two chunks using f.
|
|
2942
|
-
*
|
|
2943
|
-
* @example
|
|
2944
|
-
* ```ts
|
|
2945
|
-
* import { Chunk } from "effect"
|
|
2946
|
-
* import * as Result from "effect/Result"
|
|
2947
|
-
*
|
|
2948
|
-
* const chunk = Chunk.make("1", "hello", "2", "world", "3")
|
|
2949
|
-
* const [errors, numbers] = Chunk.partitionMap(chunk, (str) => {
|
|
2950
|
-
* const num = parseInt(str)
|
|
2951
|
-
* return isNaN(num)
|
|
2952
|
-
* ? Result.fail(`"${str}" is not a number`)
|
|
2953
|
-
* : Result.succeed(num)
|
|
2954
|
-
* })
|
|
2955
|
-
*
|
|
2956
|
-
* console.log(Chunk.toArray(errors)) // ['"hello" is not a number', '"world" is not a number']
|
|
2957
|
-
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
2958
|
-
*
|
|
2959
|
-
* // All successes
|
|
2960
|
-
* const validNumbers = Chunk.make("1", "2", "3")
|
|
2961
|
-
* const [noErrors, allNumbers] = Chunk.partitionMap(
|
|
2962
|
-
* validNumbers,
|
|
2963
|
-
* (str) => Result.succeed(parseInt(str))
|
|
2964
|
-
* )
|
|
2965
|
-
* console.log(Chunk.toArray(noErrors)) // []
|
|
2966
|
-
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3]
|
|
2967
|
-
* ```
|
|
2968
|
-
*
|
|
2969
|
-
* @category filtering
|
|
2970
|
-
* @since 2.0.0
|
|
2971
|
-
*/
|
|
2972
|
-
export const partitionMap: {
|
|
2973
|
-
/**
|
|
2974
|
-
* Partitions the elements of this chunk into two chunks using f.
|
|
2975
|
-
*
|
|
2976
|
-
* @example
|
|
2977
|
-
* ```ts
|
|
2978
|
-
* import { Chunk } from "effect"
|
|
2979
|
-
* import * as Result from "effect/Result"
|
|
2980
|
-
*
|
|
2981
|
-
* const chunk = Chunk.make("1", "hello", "2", "world", "3")
|
|
2982
|
-
* const [errors, numbers] = Chunk.partitionMap(chunk, (str) => {
|
|
2983
|
-
* const num = parseInt(str)
|
|
2984
|
-
* return isNaN(num)
|
|
2985
|
-
* ? Result.fail(`"${str}" is not a number`)
|
|
2986
|
-
* : Result.succeed(num)
|
|
2987
|
-
* })
|
|
2988
|
-
*
|
|
2989
|
-
* console.log(Chunk.toArray(errors)) // ['"hello" is not a number', '"world" is not a number']
|
|
2990
|
-
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
2991
|
-
*
|
|
2992
|
-
* // All successes
|
|
2993
|
-
* const validNumbers = Chunk.make("1", "2", "3")
|
|
2994
|
-
* const [noErrors, allNumbers] = Chunk.partitionMap(
|
|
2995
|
-
* validNumbers,
|
|
2996
|
-
* (str) => Result.succeed(parseInt(str))
|
|
2997
|
-
* )
|
|
2998
|
-
* console.log(Chunk.toArray(noErrors)) // []
|
|
2999
|
-
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3]
|
|
3000
|
-
* ```
|
|
3001
|
-
*
|
|
3002
|
-
* @category filtering
|
|
3003
|
-
* @since 2.0.0
|
|
3004
|
-
*/
|
|
3005
|
-
<A, B, C>(f: (a: A) => Result<C, B>): (self: Chunk<A>) => [left: Chunk<B>, right: Chunk<C>]
|
|
3006
|
-
/**
|
|
3007
|
-
* Partitions the elements of this chunk into two chunks using f.
|
|
3008
|
-
*
|
|
3009
|
-
* @example
|
|
3010
|
-
* ```ts
|
|
3011
|
-
* import { Chunk } from "effect"
|
|
3012
|
-
* import * as Result from "effect/Result"
|
|
3013
|
-
*
|
|
3014
|
-
* const chunk = Chunk.make("1", "hello", "2", "world", "3")
|
|
3015
|
-
* const [errors, numbers] = Chunk.partitionMap(chunk, (str) => {
|
|
3016
|
-
* const num = parseInt(str)
|
|
3017
|
-
* return isNaN(num)
|
|
3018
|
-
* ? Result.fail(`"${str}" is not a number`)
|
|
3019
|
-
* : Result.succeed(num)
|
|
3020
|
-
* })
|
|
3021
|
-
*
|
|
3022
|
-
* console.log(Chunk.toArray(errors)) // ['"hello" is not a number', '"world" is not a number']
|
|
3023
|
-
* console.log(Chunk.toArray(numbers)) // [1, 2, 3]
|
|
3024
|
-
*
|
|
3025
|
-
* // All successes
|
|
3026
|
-
* const validNumbers = Chunk.make("1", "2", "3")
|
|
3027
|
-
* const [noErrors, allNumbers] = Chunk.partitionMap(
|
|
3028
|
-
* validNumbers,
|
|
3029
|
-
* (str) => Result.succeed(parseInt(str))
|
|
3030
|
-
* )
|
|
3031
|
-
* console.log(Chunk.toArray(noErrors)) // []
|
|
3032
|
-
* console.log(Chunk.toArray(allNumbers)) // [1, 2, 3]
|
|
3033
|
-
* ```
|
|
3034
|
-
*
|
|
3035
|
-
* @category filtering
|
|
3036
|
-
* @since 2.0.0
|
|
3037
|
-
*/
|
|
3038
|
-
<A, B, C>(self: Chunk<A>, f: (a: A) => Result<C, B>): [left: Chunk<B>, right: Chunk<C>]
|
|
3039
|
-
} = dual(2, <A, B, C>(self: Chunk<A>, f: (a: A) => Result<C, B>): [left: Chunk<B>, right: Chunk<C>] =>
|
|
3040
|
-
pipe(
|
|
3041
|
-
RA.partitionMap(toReadonlyArray(self), f),
|
|
3042
|
-
([l, r]) => [fromArrayUnsafe(l), fromArrayUnsafe(r)]
|
|
3043
|
-
))
|
|
3044
|
-
|
|
3045
2858
|
/**
|
|
3046
2859
|
* Partitions the elements of this chunk into two chunks.
|
|
3047
2860
|
*
|