Module map_ordered

Module map_ordered 

Source
Expand description

Map ordered operator - transforms stream items while preserving temporal ordering.

The map_ordered operator applies a transformation function to each item in the stream while maintaining the original temporal ordering.

§Characteristics

  • Chainable: Returns a stream that can be further chained
  • Timestamp-preserving: Original timestamps are maintained
  • Lazy: Transformations are applied only when items are polled
  • Type-flexible: Can transform between different types
  • Error-passthrough: Errors pass through unchanged

§Example

use fluxion_stream::{IntoFluxionStream, MapOrderedExt};
use fluxion_test_utils::Sequenced;
use futures::StreamExt;

let (tx, rx) = async_channel::unbounded();

// Transform integers to their doubles
let mut stream = rx.into_fluxion_stream()
    .map_ordered(|n: Sequenced<i32>| Sequenced::new(n.into_inner() * 2));

tx.try_send(Sequenced::new(1)).unwrap();
tx.try_send(Sequenced::new(2)).unwrap();
tx.try_send(Sequenced::new(3)).unwrap();
drop(tx);

assert_eq!(stream.next().await.unwrap().unwrap().into_inner(), 2);
assert_eq!(stream.next().await.unwrap().unwrap().into_inner(), 4);
assert_eq!(stream.next().await.unwrap().unwrap().into_inner(), 6);

§Use Cases

  • Data transformation: Convert between types or modify values
  • Normalization: Scale or adjust values consistently
  • Extraction: Pull specific fields from complex types
  • Enrichment: Add computed properties to data

Traits§

MapOrderedExt
Extension trait providing the map_ordered operator for streams.