Logo

Programming-Idioms

  • Pascal
  • Rust
  • Dart
  • Ruby

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

adder = -> a, b { a + b }
add_two = adder.curry.(2)
add_two.(5) # => 7
fn add(a: u32, b: u32) -> u32 {
    a + b
}

let add5 = move |x| add(5, x);
 
curry(f(a, b), a) => (b) => f(a, b);

Simple currying of binary funtion.
(def rev-key #(update %2 %1 reverse))

(def rev-a (partial rev-key :a))

New implementation...
< >
Adrian