@adviser/cement - v0.0.0
    Preparing search index...

    Function streamMap

    • Transforms a ReadableStream by applying a mapping function to each chunk.

      Similar to Array.map() but for streams. Supports both sync and async mapping functions. Calls optional Close callback when stream ends.

      Type Parameters

      • T

        Input chunk type

      • U

        Output chunk type

      Parameters

      • s: ReadableStream<T>

        The input ReadableStream

      • sm: StreamMap<T, U>

        StreamMap object with Map function and optional Close callback

      Returns ReadableStream<U>

      ReadableStream with transformed chunks

      const numberStream = getNumberStream();
      const doubled = streamMap(numberStream, {
      Map: (n) => n * 2,
      Close: () => console.log('Stream ended')
      });

      // Async transformation
      const enriched = streamMap(userStream, {
      Map: async (user) => {
      const details = await fetchUserDetails(user.id);
      return { ...user, ...details };
      }
      });