Skip to content

Commit

Permalink
Merge pull request skim-rs#38 from akiradeveloper/refactor-filter-map
Browse files Browse the repository at this point in the history
refactor: use filter_map instead of map then filter
  • Loading branch information
lotabout authored Jan 17, 2017
2 parents 3b308a9 + 9dc8b92 commit 8f20286
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ impl Matcher {

matcher_engine.as_ref().map(|mat| {
let matched_items: MatchedItemGroup = items.into_iter()
.map(|item| mat.match_item(item))
.filter(Option::is_some)
.map(|item| item.unwrap())
.filter_map(|item| mat.match_item(item))
.collect();
let _ = self.tx_result.send((Event::EvModelNewItem, Box::new(matched_items)));
});
Expand Down
8 changes: 2 additions & 6 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ impl ReaderOption {

if let Some(transform_fields) = options.opt_str("with-nth") {
self.transform_fields = transform_fields.split(',')
.map(|string| {
.filter_map(|string| {
parse_range(string)
})
.filter(|range| range.is_some())
.map(|range| range.unwrap())
.collect();
}

if let Some(matching_fields) = options.opt_str("nth") {
self.matching_fields = matching_fields.split(',')
.map(|string| {
.filter_map(|string| {
parse_range(string)
})
.filter(|range| range.is_some())
.map(|range| range.unwrap())
.collect();
}
}
Expand Down

0 comments on commit 8f20286

Please sign in to comment.