Skip to content

Instantly share code, notes, and snippets.

@mmmpa
Last active August 31, 2019 02:54
Show Gist options
  • Save mmmpa/83b533e1a222b606381e8e3eee0b06a5 to your computer and use it in GitHub Desktop.
Save mmmpa/83b533e1a222b606381e8e3eee0b06a5 to your computer and use it in GitHub Desktop.
fn prepare<A: Clone + 'static, B: Clone, C, AB: Fn(A, B) -> C + 'static>(op: AB) -> Box<dyn Fn(A) -> Box<dyn Fn(B) -> C>> {
let op_rc = Rc::new(op);
Box::new(
move |a: A| {
let a_rc = Rc::new(a.clone());
let op_rc = op_rc.clone();
Box::new(move |b: B| {
let a = a_rc.as_ref();
let op = op_rc.as_ref();
op(a.clone(), b.clone())
})
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment