From 0c1b07c30cd4451d171429421d03735c7aef991c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Fri, 16 Mar 2018 02:42:56 +0100 Subject: [PATCH] Simplify `parse` function using `flat_map` --- ofborg/src/commentparser.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ofborg/src/commentparser.rs b/ofborg/src/commentparser.rs index d205cee..cc22192 100644 --- a/ofborg/src/commentparser.rs +++ b/ofborg/src/commentparser.rs @@ -1,14 +1,11 @@ pub fn parse(text: &str) -> Option> { let instructions: Vec = text.lines() - .map(|s| match parse_line(s) { - Some(instructions) => instructions, - None => vec![], + .flat_map(|s| match parse_line(s) { + Some(instructions) => instructions.into_iter(), + None => Vec::new().into_iter(), }) - .fold(vec![], |mut collector, mut inst| { - collector.append(&mut inst); - collector - }); + .collect(); if instructions.len() == 0 { return None;