Currying: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,158: Line 1,158:


This is a simple currying function written in [[Rust]]:
This is a simple currying function written in [[Rust]]:
<lang rust>#![feature(box_syntax)]
<lang rust>#![feature(conservative_impl_trait)]
fn add_n(n : i32) -> Box<Fn(i32) -> i32 + 'static> {
fn add_n<'a>(n : i32) -> impl Fn(i32) -> i32 + 'a {
box move |&: x| n + x
move |x| n + x
}
}


Line 1,167: Line 1,167:
println!("The answer to life is {}.", adder(2));
println!("The answer to life is {}.", adder(2));
}</lang>
}</lang>

Note that once "unboxed, abstract return types" are supported it can be done without the heap allocation/trait object indirection.


=={{header|Scala}}==
=={{header|Scala}}==