Trait SequenceExt

Source
pub trait SequenceExt<'gc>: Sized + Sequence<'gc> {
    // Provided methods
    fn map<F, R>(self, f: F) -> Map<Self, F>
       where F: 'static + FnOnce(Self::Output) -> R { ... }
    fn map_with<C, F, R>(self, c: C, f: F) -> MapWith<Self, C, F>
       where C: Collect,
             F: 'static + FnOnce(C, Self::Output) -> R { ... }
    fn then<F, R>(self, f: F) -> Then<'gc, Self, F>
       where Self::Output: Collect,
             F: 'static + FnOnce(MutationContext<'gc, '_>, Self::Output) -> R { ... }
    fn then_with<C, F, R>(self, c: C, f: F) -> ThenWith<'gc, Self, C, F>
       where C: Collect,
             Self::Output: Collect,
             F: 'static + FnOnce(MutationContext<'gc, '_>, C, Self::Output) -> R { ... }
    fn chain<F, R>(self, f: F) -> Flatten<'gc, Then<'gc, Self, F>>
       where Self::Output: Collect,
             F: 'static + FnOnce(MutationContext<'gc, '_>, Self::Output) -> R,
             R: Sequence<'gc> { ... }
    fn chain_with<C, F, R>(
        self,
        c: C,
        f: F,
    ) -> Flatten<'gc, ThenWith<'gc, Self, C, F>>
       where C: Collect,
             Self::Output: Collect,
             F: 'static + FnOnce(MutationContext<'gc, '_>, C, Self::Output) -> R,
             R: Sequence<'gc> { ... }
    fn flatten(self) -> Flatten<'gc, Self>
       where Self::Output: Sequence<'gc> { ... }
    fn boxed(self) -> Box<dyn Sequence<'gc, Output = Self::Output> + 'gc>
       where Self: 'gc { ... }
}
Expand description

Extension trait for Sequence that provides useful combinator methods.

Provided Methods§

Source

fn map<F, R>(self, f: F) -> Map<Self, F>
where F: 'static + FnOnce(Self::Output) -> R,

Map a function over result of this sequence.

The given function is run in the same call to Sequence::step that produces the result of this sequence.

Source

fn map_with<C, F, R>(self, c: C, f: F) -> MapWith<Self, C, F>
where C: Collect, F: 'static + FnOnce(C, Self::Output) -> R,

Equivalent to SequencExt::map but calls the function with a context parameter.

The context parameter can be anything that implements Collect. It exists to allow closures to manually close over variables that implement Collect, because there is no way currently for closure types to automatically implement Collect and are thus required to be ’static.

Source

fn then<F, R>(self, f: F) -> Then<'gc, Self, F>
where Self::Output: Collect, F: 'static + FnOnce(MutationContext<'gc, '_>, Self::Output) -> R,

Execute a separate sequence step after this sequence completes.

The given function is run in a separate Sequence::step call from the one that produces the result of this sequence.

Source

fn then_with<C, F, R>(self, c: C, f: F) -> ThenWith<'gc, Self, C, F>
where C: Collect, Self::Output: Collect, F: 'static + FnOnce(MutationContext<'gc, '_>, C, Self::Output) -> R,

Equivalent to SequenceExt::then but calls the function with the given context parameter.

The context parameter can be anything that implements Collect, it exists to allow closures to manually close over variables that implement Collect, because there is no way currently for closure types to automatically themselves implement Collect and are thus required to be ’static.

Source

fn chain<F, R>(self, f: F) -> Flatten<'gc, Then<'gc, Self, F>>
where Self::Output: Collect, F: 'static + FnOnce(MutationContext<'gc, '_>, Self::Output) -> R, R: Sequence<'gc>,

Call a function on the result of this sequence, producing a new sequence to run.

The given function is run in a separate Sequence::step call to the one that produces a result of this sequence, and the Sequence that this function results in is run in additional separate Sequence::step calls.

Source

fn chain_with<C, F, R>( self, c: C, f: F, ) -> Flatten<'gc, ThenWith<'gc, Self, C, F>>
where C: Collect, Self::Output: Collect, F: 'static + FnOnce(MutationContext<'gc, '_>, C, Self::Output) -> R, R: Sequence<'gc>,

Equivalent to SequenceExt::chain but calls the function with the given context parameter.

The context parameter can be anything that implements Collect, it exists to allow closures to manually close over variables that implement Collect, because there is no way currently for closure types to automatically themselves implement Collect and are thus required to be ’static.

Source

fn flatten(self) -> Flatten<'gc, Self>
where Self::Output: Sequence<'gc>,

If this sequence results in another sequence, this combinator flattens them so that they are executed one after another.

Source

fn boxed(self) -> Box<dyn Sequence<'gc, Output = Self::Output> + 'gc>
where Self: 'gc,

Turn this sequence into a boxed sequence type.

The return type is a dyn Sequence because where you would need to produce a boxed sequence you generally are doing this to purposefully forget what the particular sequence type is, and doing this here eases type inference.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'gc, T> SequenceExt<'gc> for T
where T: Sequence<'gc>,