pub struct Map<I, F>{ /* private fields */ }Expand description
A bulk that maps the values of bulk with f.
This struct is created by the map method on Bulk. See its
documentation for more.
§Notes about side effects
The map iterator implements DoubleEndedIterator, meaning that
you can also map backwards:
use bulks::*;
let v: [i32; 3] = [1, 2, 3].into_bulk().map(|x| x + 1).rev().collect();
assert_eq!(v, [4, 3, 2]);But if your closure has state, iterating backwards may act in a way you do not expect. Let’s go through an example. First, in the forward direction:
use bulks::*;
let mut c = 0;
for pair in ['a', 'b', 'c'].into_bulk()
.map(|letter| { c += 1; (letter, c) })
{
println!("{pair:?}");
}This will print ('a', 1), ('b', 2), ('c', 3).
Now consider this twist where we add a call to rev. This version will
print ('c', 1), ('b', 2), ('a', 3). Note that the letters are reversed,
but the values of the counter still go in order. This is because map() is
still being called lazily on each item, but we are popping items off the
back of the array now, instead of shifting them from the front.
use bulks::*;
let mut c = 0;
for pair in ['a', 'b', 'c'].into_bulk()
.map(|letter| { c += 1; (letter, c) })
.rev()
{
println!("{pair:?}");
}Trait Implementations§
Source§impl<I, F> Bulk for Map<I, F>
impl<I, F> Bulk for Map<I, F>
type MinLength = <I as Bulk>::MinLength
type MaxLength = <I as Bulk>::MaxLength
Source§fn first(self) -> Option<Self::Item>
fn first(self) -> Option<Self::Item>
Source§fn try_for_each<FF, R>(self, f: FF) -> R
fn try_for_each<FF, R>(self, f: FF) -> R
type Length = Self::Length
fn length(&self) -> Value<Self::Length>
Source§fn last(self) -> Option<Self::Item>
fn last(self) -> Option<Self::Item>
Source§fn nth<L>(self, n: L) -> Option<Self::Item>
fn nth<L>(self, n: L) -> Option<Self::Item>
n-th value, and discards the rest of the bulk. Read morefn many<NN, const N: usize>(self, n: NN) -> [Option<Self::Item>; N]
Source§fn fold<B, F>(self, init: B, f: F) -> B
fn fold<B, F>(self, init: B, f: F) -> B
fn try_fold<B, F, R>(self, init: B, f: F) -> R
fn reduce<F>(self, f: F) -> Option<Self::Item>
fn try_reduce<F, R>( self, f: F, ) -> <R::Residual as Residual<Option<R::Output>>>::TryType
Source§fn step_by<L>(self, step: L) -> StepBy<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
fn step_by<L>(self, step: L) -> StepBy<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
Source§fn chain<U>(self, other: U) -> Chain<Self, U::IntoBulk> ⓘ
fn chain<U>(self, other: U) -> Chain<Self, U::IntoBulk> ⓘ
Source§fn zip<U>(
self,
other: U,
) -> Zip<Self, <<U as IntoContained>::IntoContained as IntoBulk>::IntoBulk> ⓘwhere
Self: Sized,
U: IntoContainedBy<Self>,
fn zip<U>(
self,
other: U,
) -> Zip<Self, <<U as IntoContained>::IntoContained as IntoBulk>::IntoBulk> ⓘwhere
Self: Sized,
U: IntoContainedBy<Self>,
Source§fn intersperse(self, separator: Self::Item) -> Intersperse<Self> ⓘ
fn intersperse(self, separator: Self::Item) -> Intersperse<Self> ⓘ
separator between adjacent
items of the original bulk. Read moreSource§fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> ⓘ
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> ⓘ
separator
between adjacent items of the original bulk. Read moreSource§fn map<B, F>(self, f: F) -> Map<Self, F> ⓘ
fn map<B, F>(self, f: F) -> Map<Self, F> ⓘ
Source§fn enumerate(self) -> Enumerate<Self> ⓘwhere
Self: Sized,
fn enumerate(self) -> Enumerate<Self> ⓘwhere
Self: Sized,
Source§fn enumerate_from<U>(self, initial_count: U) -> EnumerateFrom<Self, U> ⓘ
fn enumerate_from<U>(self, initial_count: U) -> EnumerateFrom<Self, U> ⓘ
Source§fn skip<L>(self, n: L) -> Skip<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
fn skip<L>(self, n: L) -> Skip<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
n elements. Read moreSource§fn take<L>(self, n: L) -> Take<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
fn take<L>(self, n: L) -> Take<Self, L::Length<()>> ⓘwhere
Self: Sized,
L: LengthValue,
n elements, or fewer
if the underlying bulk/iterator is shorter. Read moreSource§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F> ⓘ
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F> ⓘ
Source§fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N> ⓘ
fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N> ⓘ
f for each contiguous window of size N over
self and returns a bulk of the outputs of f. The windows during mapping will overlap. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
Source§fn mutate<F>(self, f: F) -> Mutate<Self, F> ⓘ
fn mutate<F>(self, f: F) -> Mutate<Self, F> ⓘ
Source§fn collect<C, A>(self) -> Cwhere
Self: Sized,
C: FromBulk<A>,
A: CollectionAdapter<Elem = Self::Item> + CollectionStrategy<Self, C> + ?Sized,
fn collect<C, A>(self) -> Cwhere
Self: Sized,
C: FromBulk<A>,
A: CollectionAdapter<Elem = Self::Item> + CollectionStrategy<Self, C> + ?Sized,
Source§fn try_collect<C, A>(
self,
) -> <<Self::Item as Try>::Residual as Residual<C>>::TryType
fn try_collect<C, A>( self, ) -> <<Self::Item as Try>::Residual as Residual<C>>::TryType
Source§fn collect_array(
self,
) -> <Self as StaticBulk>::Array<<Self as IntoIterator>::Item>where
Self: StaticBulk,
fn collect_array(
self,
) -> <Self as StaticBulk>::Array<<Self as IntoIterator>::Item>where
Self: StaticBulk,
StaticBulk. Read moreSource§fn try_collect_array(
self,
) -> <<Self::Item as Try>::Residual as Residual<Self::Array<<Self::Item as Try>::Output>>>::TryType
fn try_collect_array( self, ) -> <<Self::Item as Try>::Residual as Residual<Self::Array<<Self::Item as Try>::Output>>>::TryType
StaticBulk. Read moreSource§fn rev(self) -> Rev<Self> ⓘwhere
Self: Sized + DoubleEndedBulk,
fn rev(self) -> Rev<Self> ⓘwhere
Self: Sized + DoubleEndedBulk,
Source§fn copied<'a, T>(self) -> Copied<Self> ⓘ
fn copied<'a, T>(self) -> Copied<Self> ⓘ
Source§fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> ⓘwhere
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> ⓘwhere
Self: Sized,
N elements of the bulk at a time. Read more