Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/en/v1/api/either/future.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ An instance of `Future`, subclass of `Promise`, whose `await` automatically retu

## Best practices

- `Future` automatically propagates the first `Left` encountered: combine it with `E.rightAsyncPipe` for your async pipelines.
- Use `Future.all([...])` to wait for multiple typed operations.
- Prefer `futureSuccess` / `futureError` to create base cases.

## See also

- [`futureSuccess`](/en/v1/api/either/futureSuccess).
- [`futureError`](/en/v1/api/either/futureError).
- [`rightAsyncPipe`](/en/v1/api/either/rightAsyncPipe) – To chain async operations.
- [`asyncGroup`](/en/v1/api/either/asyncGroup) – To aggregate asynchronous `Either` values.
4 changes: 2 additions & 2 deletions docs/en/v1/api/either/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Unwraps a `Left` payload immediately and throws if the input is not `Left`.
Chains synchronous transformations as long as results are `Right`, and stops at the first `Left`.

### [rightAsyncPipe](/en/v1/api/either/rightAsyncPipe)
Async version that accepts promises, `Future`, or `Either` and automatically stops on a `Left`.
Async version that accepts promises or `Either` and automatically stops on a `Left`.

### [group](/en/v1/api/either/group)
Aggregates multiple synchronous `Either` and returns the first `Left` or an object of `Right` values.
Expand Down Expand Up @@ -217,7 +217,7 @@ Unwraps selected `Either` payloads from an exhaustive information selector, othe
Type-level helper that returns the same Either while preserving strict Left/Right typing.

### [safeCallback](/en/v1/api/either/safeCallback)
Runs a callback and captures exceptions into a `Left<"callback">`.
Runs a callback and captures thrown errors or promise rejections into, or resolves to, a `Left<"safe-callback-error">`.

## Boolean helpers

Expand Down
27 changes: 16 additions & 11 deletions docs/en/v1/api/either/rightAsyncPipe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
outline: [2, 3]
description: "Asynchronous version of rightPipe. Automatically handles promises, Future, and Either, and short-circuits on the first Left."
description: "Asynchronous version of rightPipe. Automatically handles promises and Either, and short-circuits on the first Left."
prev:
text: "rightPipe"
link: "/en/v1/api/either/rightPipe"
Expand All @@ -11,47 +11,52 @@ next:

# rightAsyncPipe

Asynchronous version of `rightPipe`. Automatically handles promises, `Future`, and `Either`, and short-circuits on the first `Left`.
Asynchronous version of `rightPipe`. Automatically handles promises and `Either`, and short-circuits on the first `Left`.

## Interactive example

<MonacoTSEditor
src="/examples/v1/api/either/rightAsyncPipe/tryout.doc.ts"
majorVersion="v1"
height="565px"
height="523px"
/>

## Syntax

```typescript
function rightAsyncPipe<
GenericInput extends MaybeFutureEither<AnyValue>,
GenericOutputPipe1 extends MaybeFutureEither<AnyValue>
const GenericInput extends unknown,
const GenericOutputPipe1 extends unknown
>(
input: GenericInput,
pipe1: RightAsyncPipeFunction<GenericInput, GenericOutputPipe1>
): Future<RightAsyncPipeResult<GenericInput | GenericOutputPipe1, GenericOutputPipe1>>;
): Promise<
Extract<
RightAsyncPipeResult<GenericInput | GenericOutputPipe1, GenericOutputPipe1>,
any
>
>;
// ... overloads up to 15 steps
```

`RightAsyncPipeFunction` receives the unwrapped value of a `Right` (after `await`) and can return a raw value, an `Either`, or a promise/Future of these values.
`RightAsyncPipeFunction` receives the unwrapped value of a `Right` (after `await`) and can return a raw value, an `Either`, or a promise of these values.

## Parameters

- `input`: Starting `Either`, promise, or `Future`.
- `input`: Starting value, `Either`, or promise.
- `pipeX`: Async or sync functions executed sequentially. The pipeline stops on the first `Left`.

## Return value

A `Future` resolved with the last `Right` if everything succeeds, or the `Left` that interrupted the pipeline.
A `Promise` resolved with the last `Right` if everything succeeds, or the `Left` that interrupted the pipeline.

## Best practices

- Prefix your information with a clear namespace (`"user.fetch"`, `"user.validate"`) to track progress.
- Combine `rightAsyncPipe` and `rightPipe` depending on whether your steps are sync/async.
- In a `Promise`/`Future` mix, let `rightAsyncPipe` handle the normalization.
- Let `rightAsyncPipe` await each step instead of manually unwrapping intermediate promises.

## See also

- [`rightPipe`](/en/v1/api/either/rightPipe).
- [`future`](/en/v1/api/either/future) – To create `Future` values to chain.
- [`safeCallback`](/en/v1/api/either/safeCallback) – To convert thrown errors into `Either` values.
21 changes: 11 additions & 10 deletions docs/en/v1/api/either/safeCallback.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
outline: [2, 3]
description: "Runs a callback in a safe block. If the callback throws, the function returns a \"callback\" typed Left instead of propagating the exception."
description: "Runs a callback in a safe block. If the callback throws or returns a rejected promise, the function returns or resolves to a safe-callback-error Left instead of propagating the error."
prev:
text: "expect"
link: "/en/v1/api/either/expect"
Expand All @@ -11,37 +11,38 @@ next:

# safeCallback

Runs a callback in a safe block. If the callback throws, the function returns a `"callback"` typed `Left` instead of propagating the exception. If the callback returns an `Either`, it is kept as-is.
Runs a callback in a safe block. If the callback throws or returns a rejected promise, the function returns or resolves to a `"safe-callback-error"` typed `Left` instead of propagating the error. If the callback returns an `Either`, it is kept as-is. Promise results are handled after resolution.

## Interactive example

<MonacoTSEditor
src="/examples/v1/api/either/safeCallback/tryout.doc.ts"
majorVersion="v1"
height="376px"
height="565px"
/>

## Syntax

```typescript
function safeCallback<
GenericOutput extends unknown
const GenericOutput extends unknown
>(
theFunction: () => GenericOutput
): ComputeSafeCallbackResult<GenericOutput> | CallbackError;
): Extract<ComputeSafeCallbackResult<GenericOutput>, any>;
```

## Parameters

- `theFunction` : Callback to execute in a safe block.
- `theFunction`: Callback to execute in a safe block. It can return a direct value, an `Either`, or a promise of either.

## Return value

- If the callback returns an `Left` or `Right`: the `Either` is returned as-is.
- If the callback succeeds with a non-`Either` value: the value is wrapped in `CallbackSuccess`.
- If the callback throws: `CallbackError` (alias of `left("callback", error)`).
- If the callback returns a `Left` or `Right`: the `Either` is returned as-is.
- If the callback succeeds with a non-`Either` value: the value is wrapped in `SafeCallbackSuccess`.
- If the callback returns a promise: the resolved value follows the same rules.
- If the callback throws or the promise rejects: `SafeCallbackError` (`left("safe-callback-error", error)`) is returned or resolved.

## See also

- [`left`](/en/v1/api/either/left) – Build a typed `Left`.
- [`whenHasInformation`](/en/v1/api/either/whenHasInformation) – Pattern match on `"callback"`.
- [`whenHasInformation`](/en/v1/api/either/whenHasInformation) – Pattern match on `"safe-callback-error"`.
2 changes: 1 addition & 1 deletion docs/en/v1/guide/either.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if (E.isLeft(result) && E.hasInformation(result, "emailAlreadyExists")) {

When you want to chain transformations **as long as it stays a `Right`**:
- `E.rightPipe` for sync
- `E.rightAsyncPipe` for async (promises and `Future`)
- `E.rightAsyncPipe` for async pipelines based on promises

To aggregate multiple `Either`:
- `E.group` returns the first `Left`, otherwise a `Right` with all values
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/v1/api/array/withMaxElements/tryout.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ const pipeRoles = pipe(

type checkPipeRoles = ExpectType<
typeof pipeRoles,
["guest"] & A.MaxElements<1>,
readonly ["guest"] & A.MaxElements<1>,
"strict"
>;
4 changes: 2 additions & 2 deletions docs/examples/v1/api/either/bool/tryout.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { A, E, pipe, type ExpectType, equal } from "@duplojs/utils";

const result = pipe(
["duplo"],
A.find(equal("nest")),
A.find(equal("duplo")),
E.bool,
);

type check = ExpectType<
typeof result,
E.BoolFalsy<undefined> | E.BoolTruthy<"nest">,
E.BoolFalsy<undefined> | E.BoolTruthy<"duplo">,
"strict"
>;
18 changes: 8 additions & 10 deletions docs/examples/v1/api/either/rightAsyncPipe/tryout.doc.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { E, type ExpectType } from "@duplojs/utils";

const input = E.future(
Promise.resolve(
true
? false
? true
? E.right("right-1", 1)
: E.left("left-1", null)
: E.right("right-2", 2)
: E.left("left-2", 2),
),
const input = Promise.resolve(
true
? false
? true
? E.right("right-1", 1)
: E.left("left-1", null)
: E.right("right-2", 2)
: E.left("left-2", 2),
);

const result = E.rightAsyncPipe(
Expand Down
11 changes: 10 additions & 1 deletion docs/examples/v1/api/either/safeCallback/tryout.doc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { E } from "@duplojs/utils";

const success = E.safeCallback(() => 42);
// E.CallbackError | E.CallbackSuccess<number>
// E.SafeCallbackSuccess<number> | E.SafeCallbackError

const failure = E.safeCallback(() => {
throw new Error("boom");
Expand All @@ -14,3 +14,12 @@ const eitherResult = E.safeCallback(
);

const isLeft = E.isLeft(eitherResult);

const asyncSuccess = E.safeCallback(
() => Promise.resolve("done"),
);
// Promise<E.SafeCallbackSuccess<string> | E.SafeCallbackError> | E.SafeCallbackError

const asyncFailure = E.safeCallback(
() => Promise.reject(new Error("boom")),
);
3 changes: 1 addition & 2 deletions docs/fr/v1/api/either/future.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ Une instance de `Future`, sous-classe de `Promise`, dont `await` retourne automa

## Bonnes pratiques

- `Future` propage automatiquement le premier `Left` rencontré : combinez-le avec `E.rightAsyncPipe` pour vos pipelines async.
- Utilisez `Future.all([...])` pour attendre plusieurs opérations typées.
- Préférez `futureSuccess` / `futureError` pour créer des cas de base.

## Voir aussi

- [`futureSuccess`](/fr/v1/api/either/futureSuccess).
- [`futureError`](/fr/v1/api/either/futureError).
- [`rightAsyncPipe`](/fr/v1/api/either/rightAsyncPipe) – Pour chaîner des opérations async.
- [`asyncGroup`](/fr/v1/api/either/asyncGroup) – Pour agréger des valeurs `Either` asynchrones.
4 changes: 2 additions & 2 deletions docs/fr/v1/api/either/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Unwrap immédiatement le payload d'un `Left` et lève une erreur si l'entrée n'
Chaîne des transformations synchrones tant que les résultats restent `Right`, s'interrompt sur le premier `Left`.

### [rightAsyncPipe](/fr/v1/api/either/rightAsyncPipe)
Version asynchrone acceptant promesses, `Future` ou `Either` et s'arrêtant automatiquement sur un `Left`.
Version asynchrone acceptant promesses ou `Either` et s'arrêtant automatiquement sur un `Left`.

### [group](/fr/v1/api/either/group)
Agrège plusieurs `Either` synchrones et renvoie le premier `Left` ou un objet des valeurs `Right`.
Expand Down Expand Up @@ -132,7 +132,7 @@ Unwrap les payloads `Either` sélectionnés par un sélecteur exhaustif d'inform
Helper de typage qui renvoie le même Either en conservant strictement les types Left/Right.

### [safeCallback](/fr/v1/api/either/safeCallback)
Exécute un callback en capturant les exceptions dans un `Left<"callback">`.
Exécute un callback en capturant les exceptions et rejets de promesse dans, ou en résolvant vers, un `Left<"safe-callback-error">`.

## Helpers booléens

Expand Down
27 changes: 16 additions & 11 deletions docs/fr/v1/api/either/rightAsyncPipe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
outline: [2, 3]
description: "Version asynchrone de rightPipe. Gère automatiquement les promesses, Future et Either, et court-circuite sur le premier Left."
description: "Version asynchrone de rightPipe. Gère automatiquement les promesses et Either, et court-circuite sur le premier Left."
prev:
text: "rightPipe"
link: "/fr/v1/api/either/rightPipe"
Expand All @@ -11,47 +11,52 @@ next:

# rightAsyncPipe

Version asynchrone de `rightPipe`. Gère automatiquement les promesses, `Future` et `Either`, et court-circuite sur le premier `Left`.
Version asynchrone de `rightPipe`. Gère automatiquement les promesses et `Either`, et court-circuite sur le premier `Left`.

## Exemple interactif

<MonacoTSEditor
src="/examples/v1/api/either/rightAsyncPipe/tryout.doc.ts"
majorVersion="v1"
height="565px"
height="523px"
/>

## Syntaxe

```typescript
function rightAsyncPipe<
GenericInput extends MaybeFutureEither<AnyValue>,
GenericOutputPipe1 extends MaybeFutureEither<AnyValue>
const GenericInput extends unknown,
const GenericOutputPipe1 extends unknown
>(
input: GenericInput,
pipe1: RightAsyncPipeFunction<GenericInput, GenericOutputPipe1>
): Future<RightAsyncPipeResult<GenericInput | GenericOutputPipe1, GenericOutputPipe1>>;
): Promise<
Extract<
RightAsyncPipeResult<GenericInput | GenericOutputPipe1, GenericOutputPipe1>,
any
>
>;
// ... overloads jusqu'à 15 steps
```

`RightAsyncPipeFunction` reçoit la valeur unwrap d'un `Right` (après `await`) et peut retourner une valeur brute, un `Either` ou une promesse/Future de ces valeurs.
`RightAsyncPipeFunction` reçoit la valeur unwrap d'un `Right` (après `await`) et peut retourner une valeur brute, un `Either` ou une promesse de ces valeurs.

## Paramètres

- `input` : `Either`, promesse ou `Future` de départ.
- `input` : Valeur, `Either` ou promesse de départ.
- `pipeX` : Fonctions async ou sync exécutées séquentiellement. Le pipeline stoppe sur le premier `Left`.

## Valeur de retour

Une `Future` résolue avec le dernier `Right` si tout réussit, ou le `Left` qui a interrompu le pipeline.
Une `Promise` résolue avec le dernier `Right` si tout réussit, ou le `Left` qui a interrompu le pipeline.

## Bonnes pratiques

- Préfixez vos informations avec un namespace clair (`"user.fetch"`, `"user.validate"`) pour suivre l'avancement.
- Combinez `rightAsyncPipe` et `rightPipe` selon que vos étapes soient sync/async.
- En cas de mix `Promise`/`Future`, laissez `rightAsyncPipe` gérer l'uniformisation.
- Laissez `rightAsyncPipe` attendre chaque étape plutôt que d'unwrap les promesses intermédiaires à la main.

## Voir aussi

- [`rightPipe`](/fr/v1/api/either/rightPipe).
- [`future`](/fr/v1/api/either/future) – Pour créer des `Future` à chaîner.
- [`safeCallback`](/fr/v1/api/either/safeCallback) – Pour convertir les erreurs levées en valeurs `Either`.
19 changes: 10 additions & 9 deletions docs/fr/v1/api/either/safeCallback.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
outline: [2, 3]
description: "Exécute un callback dans un bloc sécurisé. Si le callback lève une erreur, la fonction renvoie un Left typé \"callback\" au lieu de propager l'exception."
description: "Exécute un callback dans un bloc sécurisé. Si le callback lève une erreur ou retourne une promesse rejetée, la fonction renvoie ou résout vers un Left safe-callback-error au lieu de propager l'erreur."
prev:
text: "expect"
link: "/fr/v1/api/either/expect"
Expand All @@ -11,37 +11,38 @@ next:

# safeCallback

Exécute un callback dans un bloc sécurisé. Si le callback lève une erreur, la fonction renvoie un `Left` typé `"callback"` au lieu de propager l'exception. Si le callback retourne un `Either`, il est conservé tel quel.
Exécute un callback dans un bloc sécurisé. Si le callback lève une erreur ou retourne une promesse rejetée, la fonction renvoie ou résout vers un `Left` typé `"safe-callback-error"` au lieu de propager l'erreur. Si le callback retourne un `Either`, il est conservé tel quel. Les résultats de promesse suivent les mêmes règles après résolution.

## Exemple interactif

<MonacoTSEditor
src="/examples/v1/api/either/safeCallback/tryout.doc.ts"
majorVersion="v1"
height="376px"
height="565px"
/>

## Syntaxe

```typescript
function safeCallback<
GenericOutput extends unknown
const GenericOutput extends unknown
>(
theFunction: () => GenericOutput
): ComputeSafeCallbackResult<GenericOutput> | CallbackError;
): Extract<ComputeSafeCallbackResult<GenericOutput>, any>;
```

## Paramètres

- `theFunction` : Callback à exécuter en mode sécurisé.
- `theFunction` : Callback à exécuter en mode sécurisé. Il peut retourner une valeur directe, un `Either` ou une promesse de l'un des deux.

## Valeur de retour

- Si le callback retourne un `Left` ou `Right` : l'`Either` est renvoyé tel quel.
- Si le callback réussit avec une valeur non `Either` : la valeur est encapsulée dans `CallbackSuccess`.
- Si le callback lève une erreur : `CallbackError` (alias de `left("callback", error)`).
- Si le callback réussit avec une valeur non `Either` : la valeur est encapsulée dans `SafeCallbackSuccess`.
- Si le callback retourne une promesse : la valeur résolue suit les mêmes règles.
- Si le callback lève une erreur ou si la promesse rejette : `SafeCallbackError` (`left("safe-callback-error", error)`) est renvoyé ou résolu.

## Voir aussi

- [`left`](/fr/v1/api/either/left) – Construire un `Left` typé.
- [`whenHasInformation`](/fr/v1/api/either/whenHasInformation) – Pattern matching sur `"callback"`.
- [`whenHasInformation`](/fr/v1/api/either/whenHasInformation) – Pattern matching sur `"safe-callback-error"`.
Loading
Loading