Skip to content

Commit

Permalink
MutableVecExt: enumerate_map added
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kolarik committed Jan 23, 2024
1 parent 43b3e39 commit 0d60ebd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/futures_signals_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub trait MutableVecExt<A> {
where
F: FnMut(&A) -> U;

fn enumerate_map<F, U>(&self, f: F) -> Vec<U>
where
F: FnMut(usize, &A) -> U;

fn filter<P>(&self, p: P) -> Vec<A>
where
A: Copy,
Expand Down Expand Up @@ -297,6 +301,17 @@ impl<A> MutableVecExt<A> for MutableVec<A> {
self.lock_ref().iter().map(f).collect()
}

fn enumerate_map<F, U>(&self, mut f: F) -> Vec<U>
where
F: FnMut(usize, &A) -> U,
{
self.lock_ref()
.iter()
.enumerate()
.map(|(index, item)| f(index, item))
.collect()
}

fn filter<P>(&self, mut p: P) -> Vec<A>
where
A: Copy,
Expand Down

0 comments on commit 0d60ebd

Please sign in to comment.