Simplify parse
function using flat_map
This commit is contained in:
parent
d473806fc4
commit
0c1b07c30c
|
@ -1,14 +1,11 @@
|
||||||
|
|
||||||
pub fn parse(text: &str) -> Option<Vec<Instruction>> {
|
pub fn parse(text: &str) -> Option<Vec<Instruction>> {
|
||||||
let instructions: Vec<Instruction> = text.lines()
|
let instructions: Vec<Instruction> = text.lines()
|
||||||
.map(|s| match parse_line(s) {
|
.flat_map(|s| match parse_line(s) {
|
||||||
Some(instructions) => instructions,
|
Some(instructions) => instructions.into_iter(),
|
||||||
None => vec![],
|
None => Vec::new().into_iter(),
|
||||||
})
|
})
|
||||||
.fold(vec![], |mut collector, mut inst| {
|
.collect();
|
||||||
collector.append(&mut inst);
|
|
||||||
collector
|
|
||||||
});
|
|
||||||
|
|
||||||
if instructions.len() == 0 {
|
if instructions.len() == 0 {
|
||||||
return None;
|
return None;
|
||||||
|
|
Loading…
Reference in a new issue