effect 3.14.22 → 3.15.1
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/cjs/Brand.js +8 -0
- package/dist/cjs/Brand.js.map +1 -1
- package/dist/cjs/Cause.js +8 -1
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/ConfigError.js.map +1 -1
- package/dist/cjs/Effect.js +18 -16
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +36 -1
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Function.js +2 -2
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/Layer.js +8 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/MutableHashMap.js.map +1 -1
- package/dist/cjs/MutableList.js.map +1 -1
- package/dist/cjs/Pipeable.js +25 -1
- package/dist/cjs/Pipeable.js.map +1 -1
- package/dist/cjs/Record.js +26 -1
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/Stream.js +23 -2
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/internal/configError.js +12 -0
- package/dist/cjs/internal/configError.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +17 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/stream.js +62 -2
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Brand.d.ts +7 -0
- package/dist/dts/Brand.d.ts.map +1 -1
- package/dist/dts/Cause.d.ts +7 -0
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/ConfigError.d.ts +2 -0
- package/dist/dts/ConfigError.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +74 -118
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +35 -0
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Function.d.ts +2 -2
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +6 -0
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/MutableHashMap.d.ts +1 -1
- package/dist/dts/MutableHashMap.d.ts.map +1 -1
- package/dist/dts/MutableList.d.ts +1 -1
- package/dist/dts/MutableList.d.ts.map +1 -1
- package/dist/dts/Pipeable.d.ts +30 -1
- package/dist/dts/Pipeable.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +86 -0
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +36 -0
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +11 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Brand.js +8 -1
- package/dist/esm/Brand.js.map +1 -1
- package/dist/esm/Cause.js +7 -0
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/ConfigError.js.map +1 -1
- package/dist/esm/Effect.js +18 -16
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +35 -0
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Function.js +2 -2
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/Layer.js +6 -0
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/MutableHashMap.js.map +1 -1
- package/dist/esm/MutableList.js.map +1 -1
- package/dist/esm/Pipeable.js +23 -0
- package/dist/esm/Pipeable.js.map +1 -1
- package/dist/esm/Record.js +25 -0
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/Stream.js +21 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/internal/configError.js +12 -0
- package/dist/esm/internal/configError.js.map +1 -1
- package/dist/esm/internal/core-effect.js +17 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/stream.js +58 -0
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Brand.ts +9 -1
- package/src/Cause.ts +8 -0
- package/src/ConfigError.ts +2 -0
- package/src/Effect.ts +176 -165
- package/src/Either.ts +107 -0
- package/src/Function.ts +2 -2
- package/src/Layer.ts +11 -0
- package/src/MutableHashMap.ts +1 -1
- package/src/MutableList.ts +1 -1
- package/src/Pipeable.ts +51 -1
- package/src/Record.ts +120 -0
- package/src/Stream.ts +40 -0
- package/src/Types.ts +13 -0
- package/src/internal/configError.ts +12 -0
- package/src/internal/core-effect.ts +72 -65
- package/src/internal/stream.ts +68 -0
- package/src/internal/version.ts +1 -1
package/src/Either.ts
CHANGED
|
@@ -1614,3 +1614,110 @@ export const transposeOption = <A = never, E = never>(
|
|
|
1614
1614
|
): Either<Option<A>, E> => {
|
|
1615
1615
|
return option_.isNone(self) ? right(option_.none) : map(self.value, option_.some)
|
|
1616
1616
|
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Applies an `Either` on an `Option` and transposes the result.
|
|
1620
|
+
*
|
|
1621
|
+
* **Details**
|
|
1622
|
+
*
|
|
1623
|
+
* If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.
|
|
1624
|
+
* If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* import { Either, Option, pipe } from "effect"
|
|
1629
|
+
*
|
|
1630
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1631
|
+
* // ▼
|
|
1632
|
+
* const noneResult = pipe(
|
|
1633
|
+
* Option.none(),
|
|
1634
|
+
* Either.transposeMapOption(() => Either.right(42)) // will not be executed
|
|
1635
|
+
* )
|
|
1636
|
+
* console.log(noneResult)
|
|
1637
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }
|
|
1638
|
+
*
|
|
1639
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1640
|
+
* // ▼
|
|
1641
|
+
* const someRightResult = pipe(
|
|
1642
|
+
* Option.some(42),
|
|
1643
|
+
* Either.transposeMapOption((value) => Either.right(value * 2))
|
|
1644
|
+
* )
|
|
1645
|
+
* console.log(someRightResult)
|
|
1646
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }
|
|
1647
|
+
* ```
|
|
1648
|
+
*
|
|
1649
|
+
* @since 3.15.0
|
|
1650
|
+
* @category Optional Wrapping & Unwrapping
|
|
1651
|
+
*/
|
|
1652
|
+
export const transposeMapOption = dual<
|
|
1653
|
+
/**
|
|
1654
|
+
* Applies an `Either` on an `Option` and transposes the result.
|
|
1655
|
+
*
|
|
1656
|
+
* **Details**
|
|
1657
|
+
*
|
|
1658
|
+
* If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.
|
|
1659
|
+
* If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* ```ts
|
|
1663
|
+
* import { Either, Option, pipe } from "effect"
|
|
1664
|
+
*
|
|
1665
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1666
|
+
* // ▼
|
|
1667
|
+
* const noneResult = pipe(
|
|
1668
|
+
* Option.none(),
|
|
1669
|
+
* Either.transposeMapOption(() => Either.right(42)) // will not be executed
|
|
1670
|
+
* )
|
|
1671
|
+
* console.log(noneResult)
|
|
1672
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }
|
|
1673
|
+
*
|
|
1674
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1675
|
+
* // ▼
|
|
1676
|
+
* const someRightResult = pipe(
|
|
1677
|
+
* Option.some(42),
|
|
1678
|
+
* Either.transposeMapOption((value) => Either.right(value * 2))
|
|
1679
|
+
* )
|
|
1680
|
+
* console.log(someRightResult)
|
|
1681
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }
|
|
1682
|
+
* ```
|
|
1683
|
+
*
|
|
1684
|
+
* @since 3.15.0
|
|
1685
|
+
* @category Optional Wrapping & Unwrapping
|
|
1686
|
+
*/
|
|
1687
|
+
<A, B, E = never>(f: (self: A) => Either<B, E>) => (self: Option<A>) => Either<Option<B>, E>,
|
|
1688
|
+
/**
|
|
1689
|
+
* Applies an `Either` on an `Option` and transposes the result.
|
|
1690
|
+
*
|
|
1691
|
+
* **Details**
|
|
1692
|
+
*
|
|
1693
|
+
* If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.
|
|
1694
|
+
* If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.
|
|
1695
|
+
*
|
|
1696
|
+
* @example
|
|
1697
|
+
* ```ts
|
|
1698
|
+
* import { Either, Option, pipe } from "effect"
|
|
1699
|
+
*
|
|
1700
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1701
|
+
* // ▼
|
|
1702
|
+
* const noneResult = pipe(
|
|
1703
|
+
* Option.none(),
|
|
1704
|
+
* Either.transposeMapOption(() => Either.right(42)) // will not be executed
|
|
1705
|
+
* )
|
|
1706
|
+
* console.log(noneResult)
|
|
1707
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }
|
|
1708
|
+
*
|
|
1709
|
+
* // ┌─── Either<Option<number>, never>>
|
|
1710
|
+
* // ▼
|
|
1711
|
+
* const someRightResult = pipe(
|
|
1712
|
+
* Option.some(42),
|
|
1713
|
+
* Either.transposeMapOption((value) => Either.right(value * 2))
|
|
1714
|
+
* )
|
|
1715
|
+
* console.log(someRightResult)
|
|
1716
|
+
* // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }
|
|
1717
|
+
* ```
|
|
1718
|
+
*
|
|
1719
|
+
* @since 3.15.0
|
|
1720
|
+
* @category Optional Wrapping & Unwrapping
|
|
1721
|
+
*/
|
|
1722
|
+
<A, B, E = never>(self: Option<A>, f: (self: A) => Either<B, E>) => Either<Option<B>, E>
|
|
1723
|
+
>(2, (self, f) => option_.isNone(self) ? right(option_.none) : map(f(self.value), option_.some))
|
package/src/Function.ts
CHANGED
|
@@ -293,7 +293,7 @@ export const dual: {
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
296
|
-
* Apply a function to
|
|
296
|
+
* Apply a function to given values.
|
|
297
297
|
*
|
|
298
298
|
* @example
|
|
299
299
|
* ```ts
|
|
@@ -306,7 +306,7 @@ export const dual: {
|
|
|
306
306
|
*
|
|
307
307
|
* @since 2.0.0
|
|
308
308
|
*/
|
|
309
|
-
export const apply = <A
|
|
309
|
+
export const apply = <A extends ReadonlyArray<unknown>>(...a: A) => <B>(self: (...a: A) => B): B => self(...a)
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
312
|
* A lazy argument.
|
package/src/Layer.ts
CHANGED
|
@@ -32,9 +32,11 @@ import * as fiberRuntime from "./internal/fiberRuntime.js"
|
|
|
32
32
|
import * as internal from "./internal/layer.js"
|
|
33
33
|
import * as circularLayer from "./internal/layer/circular.js"
|
|
34
34
|
import * as query from "./internal/query.js"
|
|
35
|
+
import { randomTag } from "./internal/random.js"
|
|
35
36
|
import type { LogLevel } from "./LogLevel.js"
|
|
36
37
|
import type * as Option from "./Option.js"
|
|
37
38
|
import type { Pipeable } from "./Pipeable.js"
|
|
39
|
+
import type * as Random from "./Random.js"
|
|
38
40
|
import type * as Request from "./Request.js"
|
|
39
41
|
import type * as Runtime from "./Runtime.js"
|
|
40
42
|
import type * as Schedule from "./Schedule.js"
|
|
@@ -1280,6 +1282,15 @@ export const setConfigProvider: (configProvider: ConfigProvider) => Layer<never>
|
|
|
1280
1282
|
*/
|
|
1281
1283
|
export const parentSpan: (span: Tracer.AnySpan) => Layer<Tracer.ParentSpan> = circularLayer.parentSpan
|
|
1282
1284
|
|
|
1285
|
+
/**
|
|
1286
|
+
* @since 3.15.0
|
|
1287
|
+
* @category Random
|
|
1288
|
+
*/
|
|
1289
|
+
export const setRandom = <A extends Random.Random>(random: A): Layer<never> =>
|
|
1290
|
+
scopedDiscard(
|
|
1291
|
+
fiberRuntime.fiberRefLocallyScopedWith(defaultServices.currentServices, Context.add(randomTag, random))
|
|
1292
|
+
)
|
|
1293
|
+
|
|
1283
1294
|
/**
|
|
1284
1295
|
* @since 2.0.0
|
|
1285
1296
|
* @category requests & batching
|
package/src/MutableHashMap.ts
CHANGED
|
@@ -102,7 +102,7 @@ class BucketIterator<K, V> implements Iterator<[K, V]> {
|
|
|
102
102
|
* @since 2.0.0
|
|
103
103
|
* @category constructors
|
|
104
104
|
*/
|
|
105
|
-
export const empty = <K, V>(): MutableHashMap<K, V> => {
|
|
105
|
+
export const empty = <K = never, V = never>(): MutableHashMap<K, V> => {
|
|
106
106
|
const self = Object.create(MutableHashMapProto)
|
|
107
107
|
self.referential = new Map()
|
|
108
108
|
self.buckets = new Map()
|
package/src/MutableList.ts
CHANGED
|
@@ -97,7 +97,7 @@ const makeNode = <T>(value: T): LinkedListNode<T> => ({
|
|
|
97
97
|
* @since 2.0.0
|
|
98
98
|
* @category constructors
|
|
99
99
|
*/
|
|
100
|
-
export const empty = <A>(): MutableList<A> => {
|
|
100
|
+
export const empty = <A = never>(): MutableList<A> => {
|
|
101
101
|
const list = Object.create(MutableListProto)
|
|
102
102
|
list.head = undefined
|
|
103
103
|
list.tail = undefined
|
package/src/Pipeable.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* @since 2.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import type { Ctor } from "./Types.js"
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* @since 2.0.0
|
|
7
|
-
* @category
|
|
9
|
+
* @category Models
|
|
8
10
|
*/
|
|
9
11
|
export interface Pipeable {
|
|
10
12
|
pipe<A>(this: A): A
|
|
@@ -522,3 +524,51 @@ export const pipeArguments = <A>(self: A, args: IArguments): unknown => {
|
|
|
522
524
|
}
|
|
523
525
|
}
|
|
524
526
|
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* @since 3.15.0
|
|
530
|
+
* @category Models
|
|
531
|
+
*/
|
|
532
|
+
export interface PipeableConstructor {
|
|
533
|
+
new(...args: Array<any>): Pipeable
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @since 3.15.0
|
|
538
|
+
* @category Prototypes
|
|
539
|
+
*/
|
|
540
|
+
export const Prototype: Pipeable = {
|
|
541
|
+
pipe() {
|
|
542
|
+
return pipeArguments(this, arguments)
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const Base: PipeableConstructor = (function() {
|
|
547
|
+
function PipeableBase() {}
|
|
548
|
+
PipeableBase.prototype = Prototype
|
|
549
|
+
return PipeableBase as any
|
|
550
|
+
})()
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* @since 3.15.0
|
|
554
|
+
* @category Constructors
|
|
555
|
+
*/
|
|
556
|
+
export const Class: {
|
|
557
|
+
/**
|
|
558
|
+
* @since 3.15.0
|
|
559
|
+
* @category Constructors
|
|
560
|
+
*/
|
|
561
|
+
(): PipeableConstructor
|
|
562
|
+
/**
|
|
563
|
+
* @since 3.15.0
|
|
564
|
+
* @category Constructors
|
|
565
|
+
*/
|
|
566
|
+
<TBase extends Ctor>(klass: TBase): TBase & PipeableConstructor
|
|
567
|
+
} = (klass?: Ctor) =>
|
|
568
|
+
klass ?
|
|
569
|
+
class extends klass {
|
|
570
|
+
pipe() {
|
|
571
|
+
return pipeArguments(this, arguments)
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
: Base
|
package/src/Record.ts
CHANGED
|
@@ -1883,3 +1883,123 @@ export const getEquivalence = <K extends string, A>(
|
|
|
1883
1883
|
export const singleton = <K extends string | symbol, A>(key: K, value: A): Record<K, A> => ({
|
|
1884
1884
|
[key]: value
|
|
1885
1885
|
} as any)
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Returns the first entry that satisfies the specified
|
|
1889
|
+
* predicate, or `None` if no such entry exists.
|
|
1890
|
+
*
|
|
1891
|
+
* @example
|
|
1892
|
+
* ```ts
|
|
1893
|
+
* import { Record, Option } from "effect"
|
|
1894
|
+
*
|
|
1895
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1896
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1897
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1898
|
+
* ```
|
|
1899
|
+
*
|
|
1900
|
+
* @category elements
|
|
1901
|
+
* @since 3.14.0
|
|
1902
|
+
*/
|
|
1903
|
+
export const findFirst: {
|
|
1904
|
+
/**
|
|
1905
|
+
* Returns the first entry that satisfies the specified
|
|
1906
|
+
* predicate, or `None` if no such entry exists.
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```ts
|
|
1910
|
+
* import { Record, Option } from "effect"
|
|
1911
|
+
*
|
|
1912
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1913
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1914
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1915
|
+
* ```
|
|
1916
|
+
*
|
|
1917
|
+
* @category elements
|
|
1918
|
+
* @since 3.14.0
|
|
1919
|
+
*/
|
|
1920
|
+
<K extends string | symbol, V, V2 extends V>(refinement: (value: NoInfer<V>, key: NoInfer<K>) => value is V2): (self: Record<K, V>) => Option.Option<[K, V2]>
|
|
1921
|
+
/**
|
|
1922
|
+
* Returns the first entry that satisfies the specified
|
|
1923
|
+
* predicate, or `None` if no such entry exists.
|
|
1924
|
+
*
|
|
1925
|
+
* @example
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* import { Record, Option } from "effect"
|
|
1928
|
+
*
|
|
1929
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1930
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1931
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1932
|
+
* ```
|
|
1933
|
+
*
|
|
1934
|
+
* @category elements
|
|
1935
|
+
* @since 3.14.0
|
|
1936
|
+
*/
|
|
1937
|
+
<K extends string | symbol, V>(predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean): (self: Record<K, V>) => Option.Option<[K, V]>
|
|
1938
|
+
/**
|
|
1939
|
+
* Returns the first entry that satisfies the specified
|
|
1940
|
+
* predicate, or `None` if no such entry exists.
|
|
1941
|
+
*
|
|
1942
|
+
* @example
|
|
1943
|
+
* ```ts
|
|
1944
|
+
* import { Record, Option } from "effect"
|
|
1945
|
+
*
|
|
1946
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1947
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1948
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1949
|
+
* ```
|
|
1950
|
+
*
|
|
1951
|
+
* @category elements
|
|
1952
|
+
* @since 3.14.0
|
|
1953
|
+
*/
|
|
1954
|
+
<K extends string | symbol, V, V2 extends V>(
|
|
1955
|
+
self: Record<K, V>,
|
|
1956
|
+
refinement: (value: NoInfer<V>, key: NoInfer<K>) => value is V2
|
|
1957
|
+
): Option.Option<[K, V2]>
|
|
1958
|
+
/**
|
|
1959
|
+
* Returns the first entry that satisfies the specified
|
|
1960
|
+
* predicate, or `None` if no such entry exists.
|
|
1961
|
+
*
|
|
1962
|
+
* @example
|
|
1963
|
+
* ```ts
|
|
1964
|
+
* import { Record, Option } from "effect"
|
|
1965
|
+
*
|
|
1966
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1967
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1968
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1969
|
+
* ```
|
|
1970
|
+
*
|
|
1971
|
+
* @category elements
|
|
1972
|
+
* @since 3.14.0
|
|
1973
|
+
*/
|
|
1974
|
+
<K extends string | symbol, V>(
|
|
1975
|
+
self: Record<K, V>,
|
|
1976
|
+
predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean
|
|
1977
|
+
): Option.Option<[K, V]>
|
|
1978
|
+
} = dual(
|
|
1979
|
+
2,
|
|
1980
|
+
<K extends string | symbol, V>(self: Record<K, V>, f: (value: V, key: K) => boolean) => {
|
|
1981
|
+
for (const a of Object.entries</**
|
|
1982
|
+
* Returns the first entry that satisfies the specified
|
|
1983
|
+
* predicate, or `None` if no such entry exists.
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```ts
|
|
1987
|
+
* import { Record, Option } from "effect"
|
|
1988
|
+
*
|
|
1989
|
+
* const record = { a: 1, b: 2, c: 3 }
|
|
1990
|
+
* const result = Record.findFirst(record, (value, key) => value > 1 && key !== "b")
|
|
1991
|
+
* console.log(result) // Option.Some(["c", 3])
|
|
1992
|
+
* ```
|
|
1993
|
+
*
|
|
1994
|
+
* @category elements
|
|
1995
|
+
* @since 3.14.0
|
|
1996
|
+
*/
|
|
1997
|
+
V>(self)) {
|
|
1998
|
+
const o = f(a[1], a[0] as K)
|
|
1999
|
+
if (o) {
|
|
2000
|
+
return Option.some(a)
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
return Option.none()
|
|
2004
|
+
}
|
|
2005
|
+
)
|
package/src/Stream.ts
CHANGED
|
@@ -9651,6 +9651,46 @@ export const toReadableStreamRuntime: {
|
|
|
9651
9651
|
): ReadableStream<A>
|
|
9652
9652
|
} = internal.toReadableStreamRuntime
|
|
9653
9653
|
|
|
9654
|
+
/**
|
|
9655
|
+
* Converts the stream to a `AsyncIterable` using the provided runtime.
|
|
9656
|
+
*
|
|
9657
|
+
* @since 3.15.0
|
|
9658
|
+
* @category destructors
|
|
9659
|
+
*/
|
|
9660
|
+
export const toAsyncIterableRuntime: {
|
|
9661
|
+
/**
|
|
9662
|
+
* Converts the stream to a `AsyncIterable` using the provided runtime.
|
|
9663
|
+
*
|
|
9664
|
+
* @since 3.15.0
|
|
9665
|
+
* @category destructors
|
|
9666
|
+
*/
|
|
9667
|
+
<A, XR>(runtime: Runtime<XR>): <E, R extends XR>(self: Stream<A, E, R>) => AsyncIterable<A>
|
|
9668
|
+
/**
|
|
9669
|
+
* Converts the stream to a `AsyncIterable` using the provided runtime.
|
|
9670
|
+
*
|
|
9671
|
+
* @since 3.15.0
|
|
9672
|
+
* @category destructors
|
|
9673
|
+
*/
|
|
9674
|
+
<A, E, XR, R extends XR>(self: Stream<A, E, R>, runtime: Runtime<XR>): AsyncIterable<A>
|
|
9675
|
+
} = internal.toAsyncIterableRuntime
|
|
9676
|
+
|
|
9677
|
+
/**
|
|
9678
|
+
* Converts the stream to a `AsyncIterable` capturing the required dependencies.
|
|
9679
|
+
*
|
|
9680
|
+
* @since 3.15.0
|
|
9681
|
+
* @category destructors
|
|
9682
|
+
*/
|
|
9683
|
+
export const toAsyncIterableEffect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<AsyncIterable<A>, never, R> =
|
|
9684
|
+
internal.toAsyncIterableEffect
|
|
9685
|
+
|
|
9686
|
+
/**
|
|
9687
|
+
* Converts the stream to a `AsyncIterable`.
|
|
9688
|
+
*
|
|
9689
|
+
* @since 3.15.0
|
|
9690
|
+
* @category destructors
|
|
9691
|
+
*/
|
|
9692
|
+
export const toAsyncIterable: <A, E>(self: Stream<A, E>) => AsyncIterable<A> = internal.toAsyncIterable
|
|
9693
|
+
|
|
9654
9694
|
/**
|
|
9655
9695
|
* Applies the transducer to the stream and emits its outputs.
|
|
9656
9696
|
*
|
package/src/Types.ts
CHANGED
|
@@ -144,6 +144,14 @@ export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
|
|
|
144
144
|
>() => T extends Y ? 1 : 2 ? true
|
|
145
145
|
: false
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Determines if two types are equal, allowing to specify the return types.
|
|
149
|
+
*
|
|
150
|
+
* @since 3.15.0
|
|
151
|
+
* @category models
|
|
152
|
+
*/
|
|
153
|
+
export type EqualsWith<A, B, Y, N> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? Y : N
|
|
154
|
+
|
|
147
155
|
/**
|
|
148
156
|
* Determines if a record contains any of the given keys.
|
|
149
157
|
*
|
|
@@ -336,3 +344,8 @@ export type NotFunction<T> = T extends Function ? never : T
|
|
|
336
344
|
* @since 3.9.0
|
|
337
345
|
*/
|
|
338
346
|
export type NoExcessProperties<T, U> = T & { readonly [K in Exclude<keyof U, keyof T>]: never }
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* @since 3.15.0
|
|
350
|
+
*/
|
|
351
|
+
export type Ctor<T = {}> = new(...args: Array<any>) => T
|
|
@@ -32,6 +32,12 @@ export const And = (self: ConfigError.ConfigError, that: ConfigError.ConfigError
|
|
|
32
32
|
return `${this.left} and ${this.right}`
|
|
33
33
|
}
|
|
34
34
|
})
|
|
35
|
+
Object.defineProperty(error, "message", {
|
|
36
|
+
enumerable: false,
|
|
37
|
+
get(this: ConfigError.And) {
|
|
38
|
+
return this.toString()
|
|
39
|
+
}
|
|
40
|
+
})
|
|
35
41
|
return error
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -47,6 +53,12 @@ export const Or = (self: ConfigError.ConfigError, that: ConfigError.ConfigError)
|
|
|
47
53
|
return `${this.left} or ${this.right}`
|
|
48
54
|
}
|
|
49
55
|
})
|
|
56
|
+
Object.defineProperty(error, "message", {
|
|
57
|
+
enumerable: false,
|
|
58
|
+
get(this: ConfigError.Or) {
|
|
59
|
+
return this.toString()
|
|
60
|
+
}
|
|
61
|
+
})
|
|
50
62
|
return error
|
|
51
63
|
}
|
|
52
64
|
|
|
@@ -237,21 +237,36 @@ export const catchSomeDefect = dual<
|
|
|
237
237
|
|
|
238
238
|
/* @internal */
|
|
239
239
|
export const catchTag = dual<
|
|
240
|
-
<K extends
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
<A, E, R, K extends (E extends { _tag: string } ? E["_tag"] : never), R1, E1, A1>(
|
|
240
|
+
<E, const K extends Arr.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, A1, E1, R1>(
|
|
241
|
+
...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect.Effect<A1, E1, R1>]
|
|
242
|
+
) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>,
|
|
243
|
+
<A, E, R, const K extends Arr.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, R1, E1, A1>(
|
|
245
244
|
self: Effect.Effect<A, E, R>,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
): Effect.Effect<A | A1, Exclude<E, { _tag: K }> | E1, R | R1> =>
|
|
254
|
-
|
|
245
|
+
...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect.Effect<A1, E1, R1>]
|
|
246
|
+
) => Effect.Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
|
|
247
|
+
>(
|
|
248
|
+
(args: any) => core.isEffect(args[0]),
|
|
249
|
+
<A, E, R, const K extends Arr.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, R1, E1, A1>(
|
|
250
|
+
self: Effect.Effect<A, E, R>,
|
|
251
|
+
...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect.Effect<A1, E1, R1>]
|
|
252
|
+
): Effect.Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1> => {
|
|
253
|
+
const f = args[args.length - 1] as any
|
|
254
|
+
let predicate: Predicate.Predicate<E>
|
|
255
|
+
if (args.length === 2) {
|
|
256
|
+
predicate = Predicate.isTagged(args[0] as string)
|
|
257
|
+
} else {
|
|
258
|
+
predicate = (e) => {
|
|
259
|
+
const tag = Predicate.hasProperty(e, "_tag") ? e["_tag"] : undefined
|
|
260
|
+
if (!tag) return false
|
|
261
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
262
|
+
if (args[i] === tag) return true
|
|
263
|
+
}
|
|
264
|
+
return false
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return core.catchIf(self, predicate as Predicate.Refinement<E, Extract<E, { _tag: K[number] }>>, f) as any
|
|
268
|
+
}
|
|
269
|
+
)
|
|
255
270
|
|
|
256
271
|
/** @internal */
|
|
257
272
|
export const catchTags: {
|
|
@@ -507,7 +522,7 @@ export const filterMap = dual<
|
|
|
507
522
|
export const filterOrDie: {
|
|
508
523
|
<A, B extends A>(
|
|
509
524
|
refinement: Predicate.Refinement<Types.NoInfer<A>, B>,
|
|
510
|
-
orDieWith: (a: Types.
|
|
525
|
+
orDieWith: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => unknown
|
|
511
526
|
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>
|
|
512
527
|
<A>(
|
|
513
528
|
predicate: Predicate.Predicate<Types.NoInfer<A>>,
|
|
@@ -516,7 +531,7 @@ export const filterOrDie: {
|
|
|
516
531
|
<A, E, R, B extends A>(
|
|
517
532
|
self: Effect.Effect<A, E, R>,
|
|
518
533
|
refinement: Predicate.Refinement<A, B>,
|
|
519
|
-
orDieWith: (a: A) => unknown
|
|
534
|
+
orDieWith: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => unknown
|
|
520
535
|
): Effect.Effect<B, E, R>
|
|
521
536
|
<A, E, R>(
|
|
522
537
|
self: Effect.Effect<A, E, R>,
|
|
@@ -547,7 +562,11 @@ export const filterOrDieMessage: {
|
|
|
547
562
|
refinement: Predicate.Refinement<A, B>,
|
|
548
563
|
message: string
|
|
549
564
|
): Effect.Effect<B, E, R>
|
|
550
|
-
<A, E, R>(
|
|
565
|
+
<A, E, R>(
|
|
566
|
+
self: Effect.Effect<A, E, R>,
|
|
567
|
+
predicate: Predicate.Predicate<A>,
|
|
568
|
+
message: string
|
|
569
|
+
): Effect.Effect<A, E, R>
|
|
551
570
|
} = dual(
|
|
552
571
|
3,
|
|
553
572
|
<A, E, R>(self: Effect.Effect<A, E, R>, predicate: Predicate.Predicate<A>, message: string): Effect.Effect<A, E, R> =>
|
|
@@ -556,24 +575,24 @@ export const filterOrDieMessage: {
|
|
|
556
575
|
|
|
557
576
|
/* @internal */
|
|
558
577
|
export const filterOrElse: {
|
|
559
|
-
<A,
|
|
578
|
+
<A, C, E2, R2, B extends A>(
|
|
560
579
|
refinement: Predicate.Refinement<Types.NoInfer<A>, B>,
|
|
561
|
-
orElse: (a: Types.NoInfer<A
|
|
580
|
+
orElse: (a: Types.EqualsWith<A, B, Types.NoInfer<A>, Exclude<Types.NoInfer<A>, B>>) => Effect.Effect<C, E2, R2>
|
|
562
581
|
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B | C, E2 | E, R2 | R>
|
|
563
|
-
<A,
|
|
582
|
+
<A, C, E2, R2>(
|
|
564
583
|
predicate: Predicate.Predicate<Types.NoInfer<A>>,
|
|
565
|
-
orElse: (a: Types.NoInfer<A>) => Effect.Effect<
|
|
566
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A |
|
|
567
|
-
<A, E, R,
|
|
584
|
+
orElse: (a: Types.NoInfer<A>) => Effect.Effect<C, E2, R2>
|
|
585
|
+
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | C, E2 | E, R2 | R>
|
|
586
|
+
<A, E, R, C, E2, R2, B extends A>(
|
|
568
587
|
self: Effect.Effect<A, E, R>,
|
|
569
588
|
refinement: Predicate.Refinement<A, B>,
|
|
570
|
-
orElse: (a: A) => Effect.Effect<C, E2, R2>
|
|
589
|
+
orElse: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => Effect.Effect<C, E2, R2>
|
|
571
590
|
): Effect.Effect<B | C, E | E2, R | R2>
|
|
572
|
-
<A, E, R,
|
|
591
|
+
<A, E, R, C, E2, R2>(
|
|
573
592
|
self: Effect.Effect<A, E, R>,
|
|
574
593
|
predicate: Predicate.Predicate<A>,
|
|
575
|
-
orElse: (a: A) => Effect.Effect<
|
|
576
|
-
): Effect.Effect<A |
|
|
594
|
+
orElse: (a: A) => Effect.Effect<C, E2, R2>
|
|
595
|
+
): Effect.Effect<A | C, E | E2, R | R2>
|
|
577
596
|
} = dual(3, <A, E, R, B, E2, R2>(
|
|
578
597
|
self: Effect.Effect<A, E, R>,
|
|
579
598
|
predicate: Predicate.Predicate<A>,
|
|
@@ -586,63 +605,51 @@ export const filterOrElse: {
|
|
|
586
605
|
|
|
587
606
|
/** @internal */
|
|
588
607
|
export const liftPredicate = dual<
|
|
589
|
-
|
|
590
|
-
<
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
<A, E, B extends A>(
|
|
601
|
-
self: A,
|
|
602
|
-
refinement: Predicate.Refinement<A, B>,
|
|
603
|
-
orFailWith: (a: A) => E
|
|
604
|
-
): Effect.Effect<B, E>
|
|
605
|
-
<A, E>(
|
|
606
|
-
self: A,
|
|
607
|
-
predicate: Predicate.Predicate<Types.NoInfer<A>>,
|
|
608
|
-
orFailWith: (a: Types.NoInfer<A>) => E
|
|
609
|
-
): Effect.Effect<A, E>
|
|
610
|
-
}
|
|
608
|
+
<T extends A, E, B extends T = T, A = T>(
|
|
609
|
+
predicate: Predicate.Refinement<T, B> | Predicate.Predicate<T>,
|
|
610
|
+
orFailWith: (a: Types.EqualsWith<T, B, A, Exclude<A, B>>) => E
|
|
611
|
+
) => (a: A) => Effect.Effect<Types.EqualsWith<T, B, A, B>, E>,
|
|
612
|
+
<A, E, B extends A = A>(
|
|
613
|
+
self: A,
|
|
614
|
+
predicate: Predicate.Refinement<A, B> | Predicate.Predicate<A>,
|
|
615
|
+
orFailWith: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => E
|
|
616
|
+
) => Effect.Effect<B, E>
|
|
611
617
|
>(
|
|
612
618
|
3,
|
|
613
|
-
<A, E>(
|
|
619
|
+
<A, E, B extends A = A>(
|
|
614
620
|
self: A,
|
|
615
|
-
predicate: Predicate.Predicate
|
|
616
|
-
orFailWith: (a: Types.
|
|
617
|
-
): Effect.Effect<
|
|
621
|
+
predicate: Predicate.Refinement<A, B> | Predicate.Predicate<A>,
|
|
622
|
+
orFailWith: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => E
|
|
623
|
+
): Effect.Effect<B, E> =>
|
|
624
|
+
core.suspend(() => predicate(self) ? core.succeed(self as B) : core.fail(orFailWith(self as any)))
|
|
618
625
|
)
|
|
619
626
|
|
|
620
627
|
/* @internal */
|
|
621
628
|
export const filterOrFail: {
|
|
622
|
-
<A, B extends A
|
|
629
|
+
<A, E2, B extends A>(
|
|
623
630
|
refinement: Predicate.Refinement<Types.NoInfer<A>, B>,
|
|
624
|
-
orFailWith: (a: Types.NoInfer<A
|
|
631
|
+
orFailWith: (a: Types.EqualsWith<A, B, Types.NoInfer<A>, Exclude<Types.NoInfer<A>, B>>) => E2
|
|
625
632
|
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E2 | E, R>
|
|
626
633
|
<A, E2>(
|
|
627
634
|
predicate: Predicate.Predicate<Types.NoInfer<A>>,
|
|
628
635
|
orFailWith: (a: Types.NoInfer<A>) => E2
|
|
629
636
|
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2 | E, R>
|
|
630
|
-
<A, B extends A>(
|
|
631
|
-
refinement: Predicate.Refinement<Types.NoInfer<A>, B>
|
|
632
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementException | E, R>
|
|
633
|
-
<A>(
|
|
634
|
-
predicate: Predicate.Predicate<Types.NoInfer<A>>
|
|
635
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Cause.NoSuchElementException | E, R>
|
|
636
|
-
<A, E, R, B extends A, E2>(
|
|
637
|
+
<A, E, R, E2, B extends A>(
|
|
637
638
|
self: Effect.Effect<A, E, R>,
|
|
638
639
|
refinement: Predicate.Refinement<A, B>,
|
|
639
|
-
orFailWith: (a: A) => E2
|
|
640
|
-
): Effect.Effect<B,
|
|
640
|
+
orFailWith: (a: Types.EqualsWith<A, B, A, Exclude<A, B>>) => E2
|
|
641
|
+
): Effect.Effect<B, E2 | E, R>
|
|
641
642
|
<A, E, R, E2>(
|
|
642
643
|
self: Effect.Effect<A, E, R>,
|
|
643
644
|
predicate: Predicate.Predicate<A>,
|
|
644
645
|
orFailWith: (a: A) => E2
|
|
645
|
-
): Effect.Effect<A,
|
|
646
|
+
): Effect.Effect<A, E2 | E, R>
|
|
647
|
+
<A, B extends A>(
|
|
648
|
+
refinement: Predicate.Refinement<Types.NoInfer<A>, B>
|
|
649
|
+
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementException | E, R>
|
|
650
|
+
<A>(
|
|
651
|
+
predicate: Predicate.Predicate<Types.NoInfer<A>>
|
|
652
|
+
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Cause.NoSuchElementException | E, R>
|
|
646
653
|
<A, E, R, B extends A>(
|
|
647
654
|
self: Effect.Effect<A, E, R>,
|
|
648
655
|
refinement: Predicate.Refinement<A, B>
|