Created
September 7, 2016 21:28
-
-
Save iopq/4ee9a450b578fa9d11fa89e2d03f4afb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//does the monoid operation on the slice of tuples if the closure evaluates to true | |
fn accumulate<'a, T: Monoid>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Option<T> | |
where &'a str: Into<T> { | |
tuples.iter() | |
.filter(|&&(_,include_fn)| include_fn(i)) | |
.map(first) | |
.fold(None, |acc, concat_str| acc.op(Some(concat_str.into()))) | |
} | |
fn first<A, B>(&(one, _): (A, B)) -> A { | |
one | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment