Created
September 7, 2016 21:33
-
-
Save iopq/b0276633436af60ea3e9a6ae66053f39 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>(&(ref one, _): &(A, B)) -> A { | |
*one | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment