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