use iter once.chain(once).flatten trick to deduplicate SiteInfo generation

This commit is contained in:
Christof Petig 2020-11-23 23:28:21 +01:00
parent 49d7c40bec
commit 4563cb40ce

View File

@ -118,20 +118,16 @@ impl World {
self.civs() self.civs()
.caves .caves
.iter() .iter()
.map(|(_, info)| world_msg::SiteInfo { .map(|(_, info)| {
name: Some(info.name.clone()), // separate the two locations, combine with name
std::iter::once((info.name.clone(), info.location.0))
.chain(std::iter::once((info.name.clone(), info.location.1)))
})
.flatten() // unwrap inner iteration
.map(|(name, pos)| world_msg::SiteInfo {
name: Some(name),
kind: world_msg::SiteKind::Cave, kind: world_msg::SiteKind::Cave,
wpos: info.location.0, wpos: pos,
}),
)
.chain(
self.civs()
.caves
.iter()
.map(|(_, info)| world_msg::SiteInfo {
name: Some(info.name.clone()),
kind: world_msg::SiteKind::Cave,
wpos: info.location.1,
}), }),
) )
.collect(), .collect(),