Function tupleops::map_tuple [−][src]
pub fn map_tuple<Mapper: TupleMapper, Tpl>(
mapper: Mapper,
tpl: Tpl
) -> MapTuple<Mapper, Tpl> where
(Mapper, Tpl): TupleMap<Mapper, Tpl>,
This is supported on crate feature
map
only.Expand description
Element-wise map a tuple with a mapper.
#![feature(generic_associated_types)]
use tupleops::{TupleMapper, map_tuple};
struct MyTupleEnum(usize);
impl TupleMapper for MyTupleEnum {
type MapElem<Type> = (usize, Type);
fn map_elem<Elem>(&mut self, elem: Elem) -> Self::MapElem<Elem> {
let index = self.0;
self.0 += 1;
(index, elem)
}
}
assert_eq!(
map_tuple(MyTupleEnum(1), ("hello", "world", "!")),
((1, "hello"), (2, "world"), (3, "!")),
)
See also: MapTuple, TupleMapper, TupleMap.