@@ -20,6 +20,7 @@ module Stream exposing
2020 , Transformation
2121 , identityTransformation
2222 , identityTransformationWithOptions
23+ , nullTransformation
2324 , CustomTransformationAction(..)
2425 , customTransformation
2526 , customTransformationWithOptions
@@ -68,7 +69,7 @@ We have three kinds of streams: readable streams, writable streams, and transfor
6869
6970## Transformation Streams
7071
71- @docs Transformation, identityTransformation, identityTransformationWithOptions, CustomTransformationAction, customTransformation, customTransformationWithOptions, readable, writable, pipeThrough, awaitAndPipeThrough, pipeTo
72+ @docs Transformation, identityTransformation, identityTransformationWithOptions, nullTransformation, CustomTransformationAction, customTransformation, customTransformationWithOptions, readable, writable, pipeThrough, awaitAndPipeThrough, pipeTo
7273
7374## Useful Transformation Streams
7475
@@ -280,6 +281,7 @@ type Transformation read write =
280281
281282
282283{-| A [Transformation](#Transformation) that doesn't actually transform the data written to the writable stream.
284+
283285This can be useful as a communication primitive. You can pass the on the readable stream, allowing a one-way
284286communication to some other part of your codebase.
285287-}
@@ -304,6 +306,16 @@ identityTransformationWithOptions { readCapacity, writeCapacity } =
304306 Gren.Kernel.Stream.identityTransformation (max 1 readCapacity) (max 1 writeCapacity)
305307
306308
309+ {-| A [Transformation](#Transformation) that ignores all data written to it. The readable stream never outputs data,
310+ but is closed whenever the writable stream is closed.
311+ -}
312+ nullTransformation : data -> Task x (Transformation data data)
313+ nullTransformation initialState =
314+ customTransformation
315+ (\state _ -> UpdateState state)
316+ initialState
317+
318+
307319{-| When defining a custom [Transformation](#Transformation), you need to specify how the data coming in is handled.
308320
309321* UpdateState: Update the internal state of the [Transformation](#Transformation), no values are passed to the readable
0 commit comments