SHARE
TWEET

Untitled

a guest Jun 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     println!("{:?}", scanl(|x, y| x + y, 0, &[1, 2, 3, 4, 5]));
  3. }
  4.  
  5. fn scanl<T, F>(op: F, initial: T, list: &[T]) -> Vec<T>
  6. where
  7.     F: Fn(&T, &T) -> T,
  8. {
  9.     let mut acc = Vec::with_capacity(list.len());
  10.     acc.push(initial);
  11.  
  12.     list.iter().fold(acc, |mut acc, val| {
  13.         acc.push(op(val, acc.last().unwrap()));
  14.         acc
  15.     })
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top