@jiminp/tooltool
    Preparing search index...

    Function applyAsyncTransforms

    • Applies a sequence of asynchronous (and/or synchronous) transform functions to a value.

      This is the asynchronous version of applyTransforms. Transform functions are applied sequentially in order, with each function awaited before proceeding to the next. Each function can either:

      • Return a new transformed value (pure transformation)
      • Modify the value in-place and return undefined (impure transformation)

      Type Parameters

      • T

        The type of the value being transformed.

      Parameters

      Returns Promise<T>

      A promise that resolves to the final transformed value after all transform functions have been applied.

      // Async transformations with fetch
      const result = await applyAsyncTransforms(
      { userId: 123 },
      async (obj) => {
      const response = await fetch(`/api/users/${obj.userId}`);
      const user = await response.json();
      return { ...obj, user };
      },
      async (obj) => {
      const response = await fetch(`/api/users/${obj.userId}/posts`);
      const posts = await response.json();
      return { ...obj, posts };
      },
      );
      // result: { userId: 123, user: {...}, posts: [...] }
      // Mixing sync and async transforms
      const result = await applyAsyncTransforms(
      { count: 1 },
      (obj) => ({ ...obj, count: obj.count + 1 }), // sync
      async (obj) => {
      await someAsyncOperation();
      return { ...obj, processed: true };
      }, // async
      );
      // result: { count: 2, processed: true }