[][src]Struct bidule::Stream

pub struct Stream<'a, Sig> { /* fields omitted */ }

A stream of signals.

A stream represents a composable signal producer. When you decide to send a signal down a stream, any other streams composed with that first stream will also receive the signal. This enables to construct more interesting and complex streams by composing them via, for instance, Stream::map, Stream::filter_map, Stream::filter, Stream::fold, Stream::merge, Stream::zip, etc.

Implementations

impl<'a, Sig> Stream<'a, Sig> where
    Sig: 'a, 
[src]

pub fn new() -> Self[src]

Create a new stream.

pub fn observe<F>(&self, subscriber: F) where
    F: 'a + FnMut(&Sig), 
[src]

Observe a stream signal output flowing out of the stream.

Do not abuse this function, as its primary use is to build other combinators.

pub fn send(&self, signal: &Sig)[src]

Send a signal down the stream.

pub fn map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig> where
    F: 'a + Fn(&Sig) -> OutSig,
    OutSig: 'a, 
[src]

Map any signals flowing out of a stream.

Please note that this function is total: you cannot ignore signals. Even if you map uninteresting signals to None, you’ll still compose signals for those. If you're interested in filtering signals while mapping, have a look at the Stream::filter_map function.

pub fn filter_map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig> where
    F: 'a + Fn(&Sig) -> Option<OutSig>,
    OutSig: 'a, 
[src]

Filter and map signals flowing out of a stream.

If you’re not interested in a specific signal, you can emit None: no signal will be sent.

pub fn filter<F>(&self, pred: F) -> Self where
    F: 'a + Fn(&Sig) -> bool
[src]

Filter the signals flowing out of a stream with a predicate.

pub fn fold<F, A>(&self, value: A, f: F) -> Stream<'a, A> where
    F: 'a + Fn(A, &Sig) -> A,
    A: 'a, 
[src]

Fold all signals flowing out of a stream into a stream of values.

pub fn merge(&self, rhs: &Self) -> Self[src]

Merge two streams into one.

Merging streams enables you to perform later useful compositions, such as folding the merged results.

pub fn merge_with<F, SigRHS>(
    &self,
    rhs: &Stream<'a, SigRHS>,
    adapter: F
) -> Self where
    F: 'a + Fn(&SigRHS) -> Sig,
    SigRHS: 'a, 
[src]

Merge two streams into one with incompatible types.

This method performs the same logical operation as:

use bidule::Stream;

let stream_a = Stream::new();
let stream_b = Stream::new();
let merged = stream_a.merge(&stream_b.map(String::len));

However, because it does it in a more optimal way, you are advised to use this combinator instead.

pub fn zip<SigRHS>(
    &self,
    rhs: &Stream<'a, SigRHS>
) -> Stream<'a, Either<Sig, SigRHS>> where
    Sig: Clone,
    SigRHS: 'a + Clone
[src]

Zip two streams with each other.

The resulting stream will output Either from one or the other stream.

pub fn entangled<F, G, GSig>(f: F, g: G) -> (Self, Stream<'a, GSig>) where
    F: 'a + Fn(&Sig) -> Option<GSig>,
    G: 'a + Fn(&GSig) -> Option<Sig>,
    GSig: 'a, 
[src]

Create a pair of entangled streams.

If any of the streams sends a signal, the other one receives it. However, be careful: since the signals are defined in terms of each other, it’s quite easy to cause infinite loops if you don’t have a well-defined bottom to your recursion. This is why you’re expected to return Option<_> signals.

pub fn recv(&self) -> Receiver<Sig> where
    Sig: Clone
[src]

Sink a stream.

This method allows to receive the signal and extract it out of the stream via a channel.

impl<'a, SigA, SigB> Stream<'a, Either<SigA, SigB>> where
    SigA: 'static,
    SigB: 'static, 
[src]

pub fn unzip(&self) -> (Stream<'a, SigA>, Stream<'a, SigB>)[src]

Split a stream of zipped values into two streams.

If the Either::Left part of the stream emits a signal, it is sent to the first stream. If the Either::Right part of the tream emits, it is sent to the second stream.

Auto Trait Implementations

impl<'a, Sig> !RefUnwindSafe for Stream<'a, Sig>

impl<'a, Sig> !Send for Stream<'a, Sig>

impl<'a, Sig> !Sync for Stream<'a, Sig>

impl<'a, Sig> Unpin for Stream<'a, Sig>

impl<'a, Sig> !UnwindSafe for Stream<'a, Sig>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.