The type of the value being transformed.
The initial value to transform.
Transform functions to apply, which can be arbitrarily nested in arrays for organizational purposes.
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 }
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:
undefined(impure transformation)