diff options
author | Griffin Smith <root@gws.fyi> | 2019-07-29T01·16-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-07-29T01·16-0400 |
commit | 10fb09eca27991e878bee4a4c63d0ecd6b4a44b3 (patch) | |
tree | cbd97ef3b0047536c40ffcc8cf91383c9d5cee53 /src | |
parent | 8f3c83311f13ed28e4d8ad2875c21973ede25b1d (diff) |
Turns out, collect is the answer
Diffstat (limited to 'src')
-rw-r--r-- | src/types/entity_map.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/types/entity_map.rs b/src/types/entity_map.rs index 0f224d15ebe4..bec16cdab28a 100644 --- a/src/types/entity_map.rs +++ b/src/types/entity_map.rs @@ -42,21 +42,14 @@ impl<A> EntityMap<A> { /// Returns a list of all entities at the given position pub fn at<'a>(&'a self, pos: Position) -> Vec<&'a A> { - // self.by_position.get(&pos).iter().flat_map(|eids| { - // eids.iter() - // .map(|eid| self.by_id.get(eid).expect(BY_POS_INVARIANT)) - // }) - // gross. - match self.by_position.get(&pos) { - None => Vec::new(), - Some(eids) => { - let mut res = Vec::new(); - for eid in eids { - res.push(self.by_id.get(eid).expect(BY_POS_INVARIANT)); - } - res - } - } + self.by_position + .get(&pos) + .iter() + .flat_map(|eids| { + eids.iter() + .map(|eid| self.by_id.get(eid).expect(BY_POS_INVARIANT)) + }) + .collect() } /// Remove all entities at the given position |