effect 3.14.21 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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.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/Schema.js +14 -5
- package/dist/cjs/Schema.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 +25 -363
- 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/Schema.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.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/Schema.js +14 -5
- package/dist/esm/Schema.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 +54 -377
- 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/Schema.ts +19 -8
- 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 +70 -106
- 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/Schema.ts
CHANGED
|
@@ -9302,7 +9302,8 @@ export const TaggedError = <Self = never>(identifier?: string) =>
|
|
|
9302
9302
|
const schema = getSchemaFromFieldsOr(fieldsOr)
|
|
9303
9303
|
const newFields = { _tag: getClassTag(tag) }
|
|
9304
9304
|
const taggedFields = extendFields(newFields, fields)
|
|
9305
|
-
|
|
9305
|
+
const hasMessageField = "message" in taggedFields
|
|
9306
|
+
class TaggedErrorClass extends makeClass({
|
|
9306
9307
|
kind: "TaggedError",
|
|
9307
9308
|
identifier: identifier ?? tag,
|
|
9308
9309
|
schema: extend(schema, Struct(newFields)),
|
|
@@ -9312,13 +9313,23 @@ export const TaggedError = <Self = never>(identifier?: string) =>
|
|
|
9312
9313
|
disableToString: true
|
|
9313
9314
|
}) {
|
|
9314
9315
|
static _tag = tag
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9316
|
+
}
|
|
9317
|
+
|
|
9318
|
+
if (!hasMessageField) {
|
|
9319
|
+
Object.defineProperty(TaggedErrorClass.prototype, "message", {
|
|
9320
|
+
get() {
|
|
9321
|
+
return `{ ${
|
|
9322
|
+
util_.ownKeys(fields)
|
|
9323
|
+
.map((p: any) => `${util_.formatPropertyKey(p)}: ${util_.formatUnknown((this)[p])}`)
|
|
9324
|
+
.join(", ")
|
|
9325
|
+
} }`
|
|
9326
|
+
},
|
|
9327
|
+
enumerable: false, // mirrors the built-in Error.prototype.message, whose descriptor is also non-enumerable
|
|
9328
|
+
configurable: true
|
|
9329
|
+
})
|
|
9330
|
+
}
|
|
9331
|
+
|
|
9332
|
+
return TaggedErrorClass as any
|
|
9322
9333
|
}
|
|
9323
9334
|
|
|
9324
9335
|
const extendFields = (a: Struct.Fields, b: Struct.Fields): Struct.Fields => {
|
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
|
|