effect 3.11.8 → 3.11.9
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/Effect.js +1685 -293
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Option.js +1 -1
- package/dist/cjs/Schema.js +57 -40
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/SchemaAST.js +44 -42
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +3 -3
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +4 -4
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Effect.d.ts +12053 -8146
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +1 -1
- package/dist/dts/Schema.d.ts +1 -1
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/SchemaAST.d.ts +9 -1
- package/dist/dts/SchemaAST.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/esm/Effect.js +1734 -294
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Option.js +1 -1
- package/dist/esm/Schema.js +57 -40
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/SchemaAST.js +43 -41
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/internal/core-effect.js +3 -3
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +4 -4
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Effect.ts +7191 -3280
- package/src/Option.ts +1 -1
- package/src/Schema.ts +57 -42
- package/src/SchemaAST.ts +52 -44
- package/src/internal/core-effect.ts +11 -8
- package/src/internal/fiberRuntime.ts +14 -14
- package/src/internal/version.ts +1 -1
package/src/Option.ts
CHANGED
|
@@ -120,7 +120,7 @@ export const none = <A = never>(): Option<A> => option.none
|
|
|
120
120
|
export const some: <A>(value: A) => Option<A> = option.some
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
123
|
+
* Checks if a given value is an `Option` value.
|
|
124
124
|
*
|
|
125
125
|
* @param input - The value to check.
|
|
126
126
|
*
|
package/src/Schema.ts
CHANGED
|
@@ -793,10 +793,38 @@ export interface TemplateLiteralParser<Params extends array_.NonEmptyReadonlyArr
|
|
|
793
793
|
readonly params: Params
|
|
794
794
|
}
|
|
795
795
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
796
|
+
function getTemplateLiteralParserCoercedElement(encoded: Schema.Any, schema: Schema.Any): Schema.Any | undefined {
|
|
797
|
+
const ast = encoded.ast
|
|
798
|
+
switch (ast._tag) {
|
|
799
|
+
case "Literal": {
|
|
800
|
+
const literal = ast.literal
|
|
801
|
+
if (!Predicate.isString(literal)) {
|
|
802
|
+
const s = String(literal)
|
|
803
|
+
return transform(Literal(s), schema, {
|
|
804
|
+
strict: true,
|
|
805
|
+
decode: () => literal,
|
|
806
|
+
encode: () => s
|
|
807
|
+
})
|
|
808
|
+
}
|
|
809
|
+
break
|
|
810
|
+
}
|
|
811
|
+
case "NumberKeyword":
|
|
812
|
+
return compose(NumberFromString, schema)
|
|
813
|
+
case "Union": {
|
|
814
|
+
const members: Array<Schema.Any> = []
|
|
815
|
+
let hasCoercions = false
|
|
816
|
+
for (const member of ast.types) {
|
|
817
|
+
const schema = make(member)
|
|
818
|
+
const encoded = encodedSchema(schema)
|
|
819
|
+
const coerced = getTemplateLiteralParserCoercedElement(encoded, schema)
|
|
820
|
+
if (coerced) {
|
|
821
|
+
hasCoercions = true
|
|
822
|
+
}
|
|
823
|
+
members.push(coerced ?? schema)
|
|
824
|
+
}
|
|
825
|
+
return hasCoercions ? compose(Union(...members), schema) : schema
|
|
826
|
+
}
|
|
827
|
+
}
|
|
800
828
|
}
|
|
801
829
|
|
|
802
830
|
/**
|
|
@@ -807,49 +835,36 @@ export const TemplateLiteralParser = <Params extends array_.NonEmptyReadonlyArra
|
|
|
807
835
|
...params: Params
|
|
808
836
|
): TemplateLiteralParser<Params> => {
|
|
809
837
|
const encodedSchemas: Array<Schema.Any> = []
|
|
810
|
-
const
|
|
811
|
-
const
|
|
838
|
+
const elements: Array<Schema.Any> = []
|
|
839
|
+
const schemas: Array<Schema.Any> = []
|
|
840
|
+
let coerced = false
|
|
812
841
|
for (let i = 0; i < params.length; i++) {
|
|
813
842
|
const param = params[i]
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
843
|
+
const schema = isSchema(param) ? param : Literal(param)
|
|
844
|
+
schemas.push(schema)
|
|
845
|
+
const encoded = encodedSchema(schema)
|
|
846
|
+
encodedSchemas.push(encoded)
|
|
847
|
+
const element = getTemplateLiteralParserCoercedElement(encoded, schema)
|
|
848
|
+
if (element) {
|
|
849
|
+
elements.push(element)
|
|
850
|
+
coerced = true
|
|
821
851
|
} else {
|
|
822
|
-
|
|
823
|
-
if (Predicate.isNumber(param)) {
|
|
824
|
-
coercions[i] = Number
|
|
825
|
-
} else if (Predicate.isBigInt(param)) {
|
|
826
|
-
coercions[i] = literalValueCoercions.bigint
|
|
827
|
-
} else if (Predicate.isBoolean(param)) {
|
|
828
|
-
coercions[i] = literalValueCoercions.boolean
|
|
829
|
-
} else if (Predicate.isNull(param)) {
|
|
830
|
-
coercions[i] = literalValueCoercions.null
|
|
831
|
-
}
|
|
832
|
-
encodedSchemas.push(schema)
|
|
833
|
-
typeSchemas.push(schema)
|
|
852
|
+
elements.push(schema)
|
|
834
853
|
}
|
|
835
854
|
}
|
|
836
855
|
const from = TemplateLiteral(...encodedSchemas as any)
|
|
837
856
|
const re = AST.getTemplateLiteralCapturingRegExp(from.ast as AST.TemplateLiteral)
|
|
838
|
-
|
|
857
|
+
let to = Tuple(...elements)
|
|
858
|
+
if (coerced) {
|
|
859
|
+
to = to.annotations({ [AST.AutoTitleAnnotationId]: format(Tuple(...schemas)) })
|
|
860
|
+
}
|
|
861
|
+
return class TemplateLiteralParserClass extends transformOrFail(from, to, {
|
|
839
862
|
strict: false,
|
|
840
863
|
decode: (s, _, ast) => {
|
|
841
864
|
const match = re.exec(s)
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const coerce = coercions[i]
|
|
846
|
-
if (coerce) {
|
|
847
|
-
out[i] = coerce(out[i])
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
return ParseResult.succeed(out)
|
|
851
|
-
}
|
|
852
|
-
return ParseResult.fail(new ParseResult.Type(ast, s, `${re.source}: no match for ${JSON.stringify(s)}`))
|
|
865
|
+
return match
|
|
866
|
+
? ParseResult.succeed(match.slice(1, params.length + 1))
|
|
867
|
+
: ParseResult.fail(new ParseResult.Type(ast, s, `${re.source}: no match for ${JSON.stringify(s)}`))
|
|
853
868
|
},
|
|
854
869
|
encode: (tuple) => ParseResult.succeed(tuple.join(""))
|
|
855
870
|
}) {
|
|
@@ -9996,12 +10011,12 @@ export class BooleanFromString extends transform(
|
|
|
9996
10011
|
* @category Config validations
|
|
9997
10012
|
* @since 3.10.0
|
|
9998
10013
|
*/
|
|
9999
|
-
export const Config = <A>(name: string, schema: Schema<A,
|
|
10000
|
-
const
|
|
10014
|
+
export const Config = <A, I extends string>(name: string, schema: Schema<A, I>): config_.Config<A> => {
|
|
10015
|
+
const decodeUnknownEither = ParseResult.decodeUnknownEither(schema)
|
|
10001
10016
|
return config_.string(name).pipe(
|
|
10002
|
-
config_.mapOrFail((
|
|
10003
|
-
|
|
10004
|
-
either_.mapLeft((error) => configError_.InvalidData([], ParseResult.TreeFormatter.
|
|
10017
|
+
config_.mapOrFail((s) =>
|
|
10018
|
+
decodeUnknownEither(s).pipe(
|
|
10019
|
+
either_.mapLeft((error) => configError_.InvalidData([], ParseResult.TreeFormatter.formatIssueSync(error)))
|
|
10005
10020
|
)
|
|
10006
10021
|
)
|
|
10007
10022
|
)
|
package/src/SchemaAST.ts
CHANGED
|
@@ -1096,7 +1096,7 @@ export class Enums implements Annotated {
|
|
|
1096
1096
|
*/
|
|
1097
1097
|
export const isEnums: (ast: AST) => ast is Enums = createASTGuard("Enums")
|
|
1098
1098
|
|
|
1099
|
-
type TemplateLiteralSpanBaseType = StringKeyword | NumberKeyword | Literal
|
|
1099
|
+
type TemplateLiteralSpanBaseType = StringKeyword | NumberKeyword | Literal | TemplateLiteral
|
|
1100
1100
|
|
|
1101
1101
|
type TemplateLiteralSpanType = TemplateLiteralSpanBaseType | Union<TemplateLiteralSpanType>
|
|
1102
1102
|
|
|
@@ -1105,6 +1105,7 @@ const isTemplateLiteralSpanType = (ast: AST): ast is TemplateLiteralSpanType =>
|
|
|
1105
1105
|
case "Literal":
|
|
1106
1106
|
case "NumberKeyword":
|
|
1107
1107
|
case "StringKeyword":
|
|
1108
|
+
case "TemplateLiteral":
|
|
1108
1109
|
return true
|
|
1109
1110
|
case "Union":
|
|
1110
1111
|
return ast.types.every(isTemplateLiteralSpanType)
|
|
@@ -1120,6 +1121,8 @@ const templateLiteralSpanUnionTypeToString = (type: TemplateLiteralSpanType): st
|
|
|
1120
1121
|
return "string"
|
|
1121
1122
|
case "NumberKeyword":
|
|
1122
1123
|
return "number"
|
|
1124
|
+
case "TemplateLiteral":
|
|
1125
|
+
return String(type)
|
|
1123
1126
|
case "Union":
|
|
1124
1127
|
return type.types.map(templateLiteralSpanUnionTypeToString).join(" | ")
|
|
1125
1128
|
}
|
|
@@ -1133,6 +1136,8 @@ const templateLiteralSpanTypeToString = (type: TemplateLiteralSpanType): string
|
|
|
1133
1136
|
return "${string}"
|
|
1134
1137
|
case "NumberKeyword":
|
|
1135
1138
|
return "${number}"
|
|
1139
|
+
case "TemplateLiteral":
|
|
1140
|
+
return "${" + String(type) + "}"
|
|
1136
1141
|
case "Union":
|
|
1137
1142
|
return "${" + type.types.map(templateLiteralSpanUnionTypeToString).join(" | ") + "}"
|
|
1138
1143
|
}
|
|
@@ -2093,72 +2098,75 @@ export const keyof = (ast: AST): AST => Union.unify(_keyof(ast))
|
|
|
2093
2098
|
const STRING_KEYWORD_PATTERN = ".*"
|
|
2094
2099
|
const NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"
|
|
2095
2100
|
|
|
2096
|
-
const
|
|
2101
|
+
const getTemplateLiteralSpanTypePattern = (type: TemplateLiteralSpanType, capture: boolean): string => {
|
|
2097
2102
|
switch (type._tag) {
|
|
2103
|
+
case "Literal":
|
|
2104
|
+
return regexp.escape(String(type.literal))
|
|
2098
2105
|
case "StringKeyword":
|
|
2099
2106
|
return STRING_KEYWORD_PATTERN
|
|
2100
2107
|
case "NumberKeyword":
|
|
2101
2108
|
return NUMBER_KEYWORD_PATTERN
|
|
2102
|
-
case "
|
|
2103
|
-
return
|
|
2109
|
+
case "TemplateLiteral":
|
|
2110
|
+
return getTemplateLiteralPattern(type, capture, false)
|
|
2104
2111
|
case "Union":
|
|
2105
|
-
return type.types.map(
|
|
2112
|
+
return type.types.map((type) => getTemplateLiteralSpanTypePattern(type, capture)).join("|")
|
|
2106
2113
|
}
|
|
2107
2114
|
}
|
|
2108
2115
|
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2116
|
+
const handleTemplateLiteralSpanTypeParens = (
|
|
2117
|
+
type: TemplateLiteralSpanType,
|
|
2118
|
+
s: string,
|
|
2119
|
+
capture: boolean,
|
|
2120
|
+
top: boolean
|
|
2121
|
+
) => {
|
|
2122
|
+
if (isUnion(type)) {
|
|
2123
|
+
if (capture && !top) {
|
|
2124
|
+
return `(?:${s})`
|
|
2125
|
+
}
|
|
2126
|
+
} else if (!capture || !top) {
|
|
2127
|
+
return s
|
|
2128
|
+
}
|
|
2129
|
+
return `(${s})`
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
const getTemplateLiteralPattern = (ast: TemplateLiteral, capture: boolean, top: boolean): string => {
|
|
2133
|
+
let pattern = ``
|
|
2114
2134
|
if (ast.head !== "") {
|
|
2115
|
-
|
|
2135
|
+
const head = regexp.escape(ast.head)
|
|
2136
|
+
pattern += capture && top ? `(${head})` : head
|
|
2116
2137
|
}
|
|
2117
2138
|
|
|
2118
2139
|
for (const span of ast.spans) {
|
|
2119
|
-
const
|
|
2120
|
-
pattern +=
|
|
2140
|
+
const spanPattern = getTemplateLiteralSpanTypePattern(span.type, capture)
|
|
2141
|
+
pattern += handleTemplateLiteralSpanTypeParens(span.type, spanPattern, capture, top)
|
|
2121
2142
|
if (span.literal !== "") {
|
|
2122
|
-
|
|
2143
|
+
const literal = regexp.escape(span.literal)
|
|
2144
|
+
pattern += capture && top ? `(${literal})` : literal
|
|
2123
2145
|
}
|
|
2124
2146
|
}
|
|
2125
2147
|
|
|
2126
|
-
pattern
|
|
2127
|
-
return new RegExp(pattern)
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
const getTemplateLiteralCapturingPattern = (type: TemplateLiteralSpanType): string => {
|
|
2131
|
-
switch (type._tag) {
|
|
2132
|
-
case "StringKeyword":
|
|
2133
|
-
return STRING_KEYWORD_PATTERN
|
|
2134
|
-
case "NumberKeyword":
|
|
2135
|
-
return NUMBER_KEYWORD_PATTERN
|
|
2136
|
-
case "Literal":
|
|
2137
|
-
return regexp.escape(String(type.literal))
|
|
2138
|
-
case "Union":
|
|
2139
|
-
return type.types.map(getTemplateLiteralCapturingPattern).join("|")
|
|
2140
|
-
}
|
|
2148
|
+
return pattern
|
|
2141
2149
|
}
|
|
2142
2150
|
|
|
2143
2151
|
/**
|
|
2152
|
+
* Generates a regular expression from a `TemplateLiteral` AST node.
|
|
2153
|
+
*
|
|
2154
|
+
* @see {@link getTemplateLiteralCapturingRegExp} for a variant that captures the pattern.
|
|
2155
|
+
*
|
|
2144
2156
|
* @since 3.10.0
|
|
2145
2157
|
*/
|
|
2146
|
-
export const
|
|
2147
|
-
|
|
2148
|
-
if (ast.head !== "") {
|
|
2149
|
-
pattern += `(${regexp.escape(ast.head)})`
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
for (const span of ast.spans) {
|
|
2153
|
-
pattern += `(${getTemplateLiteralCapturingPattern(span.type)})`
|
|
2154
|
-
if (span.literal !== "") {
|
|
2155
|
-
pattern += `(${regexp.escape(span.literal)})`
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
+
export const getTemplateLiteralRegExp = (ast: TemplateLiteral): RegExp =>
|
|
2159
|
+
new RegExp(`^${getTemplateLiteralPattern(ast, false, true)}$`)
|
|
2158
2160
|
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2161
|
+
/**
|
|
2162
|
+
* Generates a regular expression that captures the pattern defined by the given `TemplateLiteral` AST.
|
|
2163
|
+
*
|
|
2164
|
+
* @see {@link getTemplateLiteralRegExp} for a variant that does not capture the pattern.
|
|
2165
|
+
*
|
|
2166
|
+
* @since 3.10.0
|
|
2167
|
+
*/
|
|
2168
|
+
export const getTemplateLiteralCapturingRegExp = (ast: TemplateLiteral): RegExp =>
|
|
2169
|
+
new RegExp(`^${getTemplateLiteralPattern(ast, true, true)}$`)
|
|
2162
2170
|
|
|
2163
2171
|
/**
|
|
2164
2172
|
* @since 3.10.0
|
|
@@ -664,23 +664,23 @@ export const filterOrFail: {
|
|
|
664
664
|
/* @internal */
|
|
665
665
|
export const findFirst: {
|
|
666
666
|
<A, E, R>(
|
|
667
|
-
|
|
667
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
|
|
668
668
|
): (elements: Iterable<A>) => Effect.Effect<Option.Option<A>, E, R>
|
|
669
669
|
<A, E, R>(
|
|
670
670
|
elements: Iterable<A>,
|
|
671
|
-
|
|
671
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
|
|
672
672
|
): Effect.Effect<Option.Option<A>, E, R>
|
|
673
673
|
} = dual(
|
|
674
674
|
2,
|
|
675
675
|
<A, E, R>(
|
|
676
676
|
elements: Iterable<A>,
|
|
677
|
-
|
|
677
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
|
|
678
678
|
): Effect.Effect<Option.Option<A>, E, R> =>
|
|
679
679
|
core.suspend(() => {
|
|
680
680
|
const iterator = elements[Symbol.iterator]()
|
|
681
681
|
const next = iterator.next()
|
|
682
682
|
if (!next.done) {
|
|
683
|
-
return findLoop(iterator, 0,
|
|
683
|
+
return findLoop(iterator, 0, predicate, next.value)
|
|
684
684
|
}
|
|
685
685
|
return core.succeed(Option.none())
|
|
686
686
|
})
|
|
@@ -762,15 +762,18 @@ export const match: {
|
|
|
762
762
|
/* @internal */
|
|
763
763
|
export const every: {
|
|
764
764
|
<A, E, R>(
|
|
765
|
-
|
|
765
|
+
predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
|
|
766
766
|
): (elements: Iterable<A>) => Effect.Effect<boolean, E, R>
|
|
767
|
-
<A, E, R>(
|
|
767
|
+
<A, E, R>(
|
|
768
|
+
elements: Iterable<A>,
|
|
769
|
+
predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
|
|
770
|
+
): Effect.Effect<boolean, E, R>
|
|
768
771
|
} = dual(
|
|
769
772
|
2,
|
|
770
773
|
<A, E, R>(
|
|
771
774
|
elements: Iterable<A>,
|
|
772
|
-
|
|
773
|
-
): Effect.Effect<boolean, E, R> => core.suspend(() => forAllLoop(elements[Symbol.iterator](), 0,
|
|
775
|
+
predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
|
|
776
|
+
): Effect.Effect<boolean, E, R> => core.suspend(() => forAllLoop(elements[Symbol.iterator](), 0, predicate))
|
|
774
777
|
)
|
|
775
778
|
|
|
776
779
|
const forAllLoop = <A, E, R>(
|
|
@@ -1705,30 +1705,30 @@ const _existsParFound = Symbol.for("effect/Effect/existsPar/found")
|
|
|
1705
1705
|
|
|
1706
1706
|
/* @internal */
|
|
1707
1707
|
export const exists: {
|
|
1708
|
-
<A, E, R>(
|
|
1708
|
+
<A, E, R>(predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>, options?: {
|
|
1709
1709
|
readonly concurrency?: Concurrency | undefined
|
|
1710
1710
|
readonly batching?: boolean | "inherit" | undefined
|
|
1711
1711
|
readonly concurrentFinalizers?: boolean | undefined
|
|
1712
1712
|
}): (elements: Iterable<A>) => Effect.Effect<boolean, E, R>
|
|
1713
|
-
<A, E, R>(elements: Iterable<A>,
|
|
1713
|
+
<A, E, R>(elements: Iterable<A>, predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>, options?: {
|
|
1714
1714
|
readonly concurrency?: Concurrency | undefined
|
|
1715
1715
|
readonly batching?: boolean | "inherit" | undefined
|
|
1716
1716
|
readonly concurrentFinalizers?: boolean | undefined
|
|
1717
1717
|
}): Effect.Effect<boolean, E, R>
|
|
1718
1718
|
} = dual(
|
|
1719
1719
|
(args) => Predicate.isIterable(args[0]) && !core.isEffect(args[0]),
|
|
1720
|
-
<A, E, R>(elements: Iterable<A>,
|
|
1720
|
+
<A, E, R>(elements: Iterable<A>, predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>, options?: {
|
|
1721
1721
|
readonly concurrency?: Concurrency | undefined
|
|
1722
1722
|
readonly batching?: boolean | "inherit" | undefined
|
|
1723
1723
|
}) =>
|
|
1724
1724
|
concurrency.matchSimple(
|
|
1725
1725
|
options?.concurrency,
|
|
1726
|
-
() => core.suspend(() => existsLoop(elements[Symbol.iterator](), 0,
|
|
1726
|
+
() => core.suspend(() => existsLoop(elements[Symbol.iterator](), 0, predicate)),
|
|
1727
1727
|
() =>
|
|
1728
1728
|
core.matchEffect(
|
|
1729
1729
|
forEach(
|
|
1730
1730
|
elements,
|
|
1731
|
-
(a, i) => core.if_(
|
|
1731
|
+
(a, i) => core.if_(predicate(a, i), { onTrue: () => core.fail(_existsParFound), onFalse: () => core.void }),
|
|
1732
1732
|
options
|
|
1733
1733
|
),
|
|
1734
1734
|
{
|
|
@@ -1757,7 +1757,7 @@ const existsLoop = <A, E, R>(
|
|
|
1757
1757
|
/* @internal */
|
|
1758
1758
|
export const filter = dual<
|
|
1759
1759
|
<A, E, R>(
|
|
1760
|
-
|
|
1760
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>,
|
|
1761
1761
|
options?: {
|
|
1762
1762
|
readonly concurrency?: Concurrency | undefined
|
|
1763
1763
|
readonly batching?: boolean | "inherit" | undefined
|
|
@@ -1765,7 +1765,7 @@ export const filter = dual<
|
|
|
1765
1765
|
readonly concurrentFinalizers?: boolean | undefined
|
|
1766
1766
|
}
|
|
1767
1767
|
) => (elements: Iterable<A>) => Effect.Effect<Array<A>, E, R>,
|
|
1768
|
-
<A, E, R>(elements: Iterable<A>,
|
|
1768
|
+
<A, E, R>(elements: Iterable<A>, predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>, options?: {
|
|
1769
1769
|
readonly concurrency?: Concurrency | undefined
|
|
1770
1770
|
readonly batching?: boolean | "inherit" | undefined
|
|
1771
1771
|
readonly negate?: boolean | undefined
|
|
@@ -1773,13 +1773,13 @@ export const filter = dual<
|
|
|
1773
1773
|
}) => Effect.Effect<Array<A>, E, R>
|
|
1774
1774
|
>(
|
|
1775
1775
|
(args) => Predicate.isIterable(args[0]) && !core.isEffect(args[0]),
|
|
1776
|
-
<A, E, R>(elements: Iterable<A>,
|
|
1776
|
+
<A, E, R>(elements: Iterable<A>, predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>, options?: {
|
|
1777
1777
|
readonly concurrency?: Concurrency | undefined
|
|
1778
1778
|
readonly batching?: boolean | "inherit" | undefined
|
|
1779
1779
|
readonly negate?: boolean | undefined
|
|
1780
1780
|
readonly concurrentFinalizers?: boolean | undefined
|
|
1781
1781
|
}) => {
|
|
1782
|
-
const
|
|
1782
|
+
const predicate_ = options?.negate ? (a: A, i: number) => core.map(predicate(a, i), Boolean.not) : predicate
|
|
1783
1783
|
return concurrency.matchSimple(
|
|
1784
1784
|
options?.concurrency,
|
|
1785
1785
|
() =>
|
|
@@ -1788,7 +1788,7 @@ export const filter = dual<
|
|
|
1788
1788
|
(effect, a, i) =>
|
|
1789
1789
|
core.zipWith(
|
|
1790
1790
|
effect,
|
|
1791
|
-
core.suspend(() =>
|
|
1791
|
+
core.suspend(() => predicate_(a, i)),
|
|
1792
1792
|
(list, b) => b ? [a, ...list] : list
|
|
1793
1793
|
),
|
|
1794
1794
|
core.sync(() => new Array<A>()) as Effect.Effect<Array<A>, E, R>
|
|
@@ -1798,7 +1798,7 @@ export const filter = dual<
|
|
|
1798
1798
|
core.map(
|
|
1799
1799
|
forEach(
|
|
1800
1800
|
elements,
|
|
1801
|
-
(a, i) => core.map(
|
|
1801
|
+
(a, i) => core.map(predicate_(a, i), (b) => (b ? Option.some(a) : Option.none())),
|
|
1802
1802
|
options
|
|
1803
1803
|
),
|
|
1804
1804
|
RA.getSomes
|
|
@@ -2706,7 +2706,7 @@ const raceAllArbiter = <E, E1, A, A1>(
|
|
|
2706
2706
|
export const reduceEffect = dual<
|
|
2707
2707
|
<Z, E, R, Eff extends Effect.Effect<any, any, any>>(
|
|
2708
2708
|
zero: Effect.Effect<Z, E, R>,
|
|
2709
|
-
f: (
|
|
2709
|
+
f: (z: NoInfer<Z>, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2710
2710
|
options?: {
|
|
2711
2711
|
readonly concurrency?: Concurrency | undefined
|
|
2712
2712
|
readonly batching?: boolean | "inherit" | undefined
|
|
@@ -2716,7 +2716,7 @@ export const reduceEffect = dual<
|
|
|
2716
2716
|
<Eff extends Effect.Effect<any, any, any>, Z, E, R>(
|
|
2717
2717
|
elements: Iterable<Eff>,
|
|
2718
2718
|
zero: Effect.Effect<Z, E, R>,
|
|
2719
|
-
f: (
|
|
2719
|
+
f: (z: NoInfer<Z>, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2720
2720
|
options?: {
|
|
2721
2721
|
readonly concurrency?: Concurrency | undefined
|
|
2722
2722
|
readonly batching?: boolean | "inherit" | undefined
|
|
@@ -2726,7 +2726,7 @@ export const reduceEffect = dual<
|
|
|
2726
2726
|
>((args) => Predicate.isIterable(args[0]) && !core.isEffect(args[0]), <A, E, R, Z>(
|
|
2727
2727
|
elements: Iterable<Effect.Effect<A, E, R>>,
|
|
2728
2728
|
zero: Effect.Effect<Z, E, R>,
|
|
2729
|
-
f: (
|
|
2729
|
+
f: (z: NoInfer<Z>, a: NoInfer<A>, i: number) => Z,
|
|
2730
2730
|
options?: {
|
|
2731
2731
|
readonly concurrency?: Concurrency | undefined
|
|
2732
2732
|
readonly batching?: boolean | "inherit" | undefined
|
package/src/internal/version.ts
CHANGED