import { Task } from './Task'; import { Either } from './Either'; /** * Represents an asynchronous computation that can fail with `L` or succeed with `R`. * 非同期計算を表し、失敗時は `L`、成功時は `R` を返します。 */ export type TaskEither = { readonly isTaskEither: true; /** * Maps the `Right` value with the provided function. * 右側の値に関数を適用します。 * @param fn - A function to transform the `Right` value. / `Right` の値を変換する関数。 */ readonly map: (fn: (value: R) => U) => TaskEither; /** * Alias of `map`. * `map` のエイリアス。 * @param fn - A function to transform the `Right` value. / `Right` の値を変換する関数。 */ readonly "<$>": (fn: (value: R) => U) => TaskEither; /** * Applies a function inside `Right` to a value inside another `TaskEither`. * 右側に入った関数を別の `TaskEither` の右側の値に適用します。 * @param boxValue - A `TaskEither` containing the value. / 値を含む `TaskEither`。 */ readonly apply: (this: TaskEither B>, boxValue: TaskEither) => TaskEither; /** * Alias of `apply`. * `apply` のエイリアス。 * @param boxValue - A `TaskEither` containing the value. / 値を含む `TaskEither`。 */ readonly "<*>": (this: TaskEither B>, boxValue: TaskEither) => TaskEither; /** * Binds the `Right` value to the next computation. * 右側の値を次の計算へ渡します。 * @param fn - A function returning `TaskEither`. / `TaskEither` を返す関数。 */ readonly flatMap: (fn: (value: R) => TaskEither) => TaskEither; /** * Alias of `flatMap`. * `flatMap` のエイリアス。 * @param fn - A function returning `TaskEither`. / `TaskEither` を返す関数。 */ readonly ">>=": (fn: (value: R) => TaskEither) => TaskEither; /** * Runs the computation and returns a Promise of `Either`. * 計算を実行し、`Either` の `Promise` を返します。 */ readonly run: () => Promise>; /** * Returns the underlying `Task>` value. * 内部の `Task>` を返します。 */ readonly toTask: () => Task>; /** * Pattern matches on `Left` or `Right` asynchronously, returning a `Task`. * `Left` または `Right` をパターンマッチし、`Task` を返します。 * @param onLeft - Handler for `Left`. / `Left` の処理関数。 * @param onRight - Handler for `Right`. / `Right` の処理関数。 */ readonly match: (onLeft: (l: L) => U, onRight: (r: R) => U) => Task; }; /** * Adapter type for Do's `$` parameter. * `$` は `yield* $(TaskEither.right(...))` のためのアダプタ関数です。 */ export type $TaskEither = (fa: TaskEither) => Generator; /** * Creates a `TaskEither` from a `Task>`. * `Task>` から `TaskEither` を作成します。 * @param fa - A task producing an Either. / `Either` を生成する `Task`。 */ declare const from: (fa: Task>) => TaskEither; /** * Lifts a value into `TaskEither` as `Right`. * 値を `Right` として `TaskEither` に持ち上げます。 * @param value - The value to lift. / 持ち上げる値。 */ declare const right: (value: R) => TaskEither; /** * Lifts an error into `TaskEither` as `Left`. * エラーを `Left` として `TaskEither` に持ち上げます。 * @param value - The error value. / エラー値。 */ declare const left: (value: L) => TaskEither; /** * Lifts a `Task` into `TaskEither` as `Right`. * `Task` を `Right` として `TaskEither` に持ち上げます。 * @param task - The task to lift. / 持ち上げる `Task`。 */ declare const fromTask: (task: Task) => TaskEither; /** * Lifts an `Either` into `TaskEither`. * `Either` を `TaskEither` に持ち上げます。 * @param e - The either to lift. / 持ち上げる `Either`。 */ declare const fromEither: (e: Either) => TaskEither; /** * Runs TaskEithers in parallel and combines results. * If any result is Left, returns the first Left (by array order) after all complete. * 複数の TaskEither を並列実行し、結果を結合します。1つでも Left があれば、配列順で最初の Left を返します(全完了後判定)。 * @param tasks - TaskEithers to run in parallel. / 並列実行する TaskEither 配列。 */ declare const all: (tasks: readonly TaskEither[]) => TaskEither; /** * Runs TaskEithers in parallel and returns all raw results without short-circuiting. * Promise.all に類似し、全件の `Either` を `Task` で返します(ショートサーキットなし)。 * @param tasks - TaskEithers to run in parallel. / 並列実行する TaskEither 配列。 */ declare const allSettled: (tasks: readonly TaskEither[]) => Task[]>; /** * Partitions results into lefts and rights without short-circuiting. * 結果を Left/Right に仕分けして返します(ショートサーキットなし)。 * @param tasks - TaskEithers to run in parallel. / 並列実行する TaskEither 配列。 */ declare const partition: (tasks: readonly TaskEither[]) => Task<[L[], R[]]>; /** * Validates all TaskEithers: accumulates all errors if any, otherwise returns all successes. * すべて成功すれば `Right(values[])`、1件以上失敗があれば `Left(errors[])` を返します。 * @param tasks - TaskEithers to run in parallel. / 並列実行する TaskEither 配列。 */ declare const validateAll: (tasks: readonly TaskEither[]) => TaskEither; /** * Traverses an array with a TaskEither-returning function and sequences the results. * 配列の各要素に関数を適用し、`TaskEither` を順に合成します。 * @param as - Input array. / 入力配列。 * @param f - Mapping function returning TaskEither. / TaskEither を返す関数。 */ declare const traverse: (as: readonly A[], f: (a: A) => TaskEither) => TaskEither; /** * Sequences a record of TaskEithers into a TaskEither of record. * レコードの TaskEither を、同構造の値のレコードへ順序付けします。 * @param obj - A record of TaskEithers. / TaskEither のレコード。 */ declare const struct: >>(obj: T) => TaskEither ? R : never; }>; /** * Creates a `TaskEither` that runs the computation, capturing thrown/rejected errors as `Left` via `onError`. * 計算を実行し、投げられた/拒否されたエラーを `onError` で `Left` に変換します。 */ declare const tryCatch: (fn: () => R | Promise, onError: (error: any) => L) => TaskEither; /** * Type guard to check if a value is `TaskEither`. * 値が `TaskEither` かどうかを判定します。 */ declare const isTaskEither: (value: any) => value is TaskEither; declare function Do(generatorFunc: () => Generator, U | TaskEither, R>): TaskEither; declare function Do(g: ($: (fa: TaskEither) => Generator) => Generator): TaskEither; /** * Utility object for `TaskEither` constructors and helpers. * `TaskEither` のコンストラクタとヘルパーをまとめたユーティリティ。 */ export declare const TaskEither: { do: typeof Do; from: typeof from; pack: typeof right; right: typeof right; left: typeof left; all: typeof all; allSettled: typeof allSettled; partition: typeof partition; validateAll: typeof validateAll; traverse: typeof traverse; struct: typeof struct; fromTask: typeof fromTask; fromEither: typeof fromEither; tryCatch: typeof tryCatch; isTaskEither: typeof isTaskEither; }; export {};