MCPcopy Create free account
hub / github.com/Effect-TS/effect / allValidate

Function allValidate

packages/effect/src/internal/fiberRuntime.ts:1886–1935  ·  view source on GitHub ↗
(
  effects: Iterable<Effect.Effect<any, any, any>>,
  reconcile: Option.Option<(as: ReadonlyArray<any>) => any>,
  options?: {
    readonly concurrency?: Concurrency | undefined
    readonly batching?: boolean | "inherit" | undefined
    readonly discard?: boolean | undefined
    readonly mode?: "default" | "validate" | "either" | undefined
    readonly concurrentFinalizers?: boolean | undefined
  }
)

Source from the content-addressed store, hash-verified

1884}
1885
1886const allValidate = (
1887 effects: Iterable<Effect.Effect<any, any, any>>,
1888 reconcile: Option.Option<(as: ReadonlyArray<any>) => any>,
1889 options?: {
1890 readonly concurrency?: Concurrency | undefined
1891 readonly batching?: boolean | "inherit" | undefined
1892 readonly discard?: boolean | undefined
1893 readonly mode?: "default" | "validate" | "either" | undefined
1894 readonly concurrentFinalizers?: boolean | undefined
1895 }
1896) => {
1897 const eitherEffects: Array<Effect.Effect<Either.Either<unknown, unknown>, never, unknown>> = []
1898 for (const effect of effects) {
1899 eitherEffects.push(core.either(effect))
1900 }
1901 return core.flatMap(
1902 forEach(eitherEffects, identity, {
1903 concurrency: options?.concurrency,
1904 batching: options?.batching,
1905 concurrentFinalizers: options?.concurrentFinalizers
1906 }),
1907 (eithers) => {
1908 const none = Option.none()
1909 const size = eithers.length
1910 const errors: Array<unknown> = new Array(size)
1911 const successes: Array<unknown> = new Array(size)
1912 let errored = false
1913 for (let i = 0; i < size; i++) {
1914 const either = eithers[i] as Either.Either<unknown, unknown>
1915 if (either._tag === "Left") {
1916 errors[i] = Option.some(either.left)
1917 errored = true
1918 } else {
1919 successes[i] = either.right
1920 errors[i] = none
1921 }
1922 }
1923 if (errored) {
1924 return reconcile._tag === "Some" ?
1925 core.fail(reconcile.value(errors)) :
1926 core.fail(errors)
1927 } else if (options?.discard) {
1928 return core.void
1929 }
1930 return reconcile._tag === "Some" ?
1931 core.succeed(reconcile.value(successes)) :
1932 core.succeed(successes)
1933 }
1934 )
1935}
1936
1937const allEither = (
1938 effects: Iterable<Effect.Effect<any, any, any>>,

Callers 1

allFunction · 0.85

Calls 4

eitherMethod · 0.80
forEachFunction · 0.70
failMethod · 0.65
valueMethod · 0.45

Tested by

no test coverage detected