Created
September 7, 2016 21:33
-
-
Save iopq/b0276633436af60ea3e9a6ae66053f39 to your computer and use it in GitHub Desktop.
Revisions
-
iopq created this gist
Sep 7, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ //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 }