Skip to content
Snippets Groups Projects
Commit cac3bbd7 authored by Per Lindgren's avatar Per Lindgren
Browse files

fallible iterator

parent b8afed80
No related branches found
No related tags found
No related merge requests found
......@@ -31,17 +31,18 @@ fn parse_num_or_id() {
type Error = String;
fn type_check(stmts: &Stmts) -> Result<(), Error> {
for i in stmts {
match i {
let r: Result<(), Error> = stmts.iter().try_for_each(|i| match i {
Stmt::Let(_, _) => {
println!("let");
Ok(())
}
Stmt::If(_, _, __) => {
println!("if");
Err("error in if".to_string())?
}
}
}
Ok(())
});
println!("here we can do something before returning");
r
}
#[test]
......@@ -49,6 +50,7 @@ fn test_stmts() {
let stmts = vec![
Stmt::Let("a".to_string(), NumOrId::Num(1)),
Stmt::Let("b".to_string(), NumOrId::Num(2)),
Stmt::If("b".to_string(), Stmts::new(), None),
Stmt::Let("c".to_string(), NumOrId::Num(3)),
];
type_check(&stmts).unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment