Skip to content

Instantly share code, notes, and snippets.

@jsanders
Last active December 24, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsanders/6785190 to your computer and use it in GitHub Desktop.
Save jsanders/6785190 to your computer and use it in GitHub Desktop.
Seeing if I can make a rust implementation of `flip` that is reminiscent of Haskell's (http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:flip)
fn flip<T>(f: ~fn(a: T, b: T)) -> ~fn(a: T, b: T) {
|a, b| { f(b, a) }
}
fn hello_world(hello: &str, world: &str) {
println!("{:s}, {:s}!", hello, world)
}
#[test]
fn test_flip() {
flip(hello_world)("hello", "world");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment