graydon/rust — Issue #1085: Add 'argument mode adapter' functions to std
Author: brson
Created: 2011-10-28 04:54:17+00:00
State: open
Labels: easy, feature, lib, unassigned

So we have a bunch of higher order functions, that usually take functions with generic, by ref parameters; then we have a bunch of standard utility functions in std::uint etc that take their arguments by value.

Both those are the correct decisions individually, but they can't be composed together:

```
// no-worky
vec::foldl(uint::sub, 0, [1,2,3]);
```

We could have a function that takes it's arguments by ref and calls another function by value:

```
fn cp_ref2(&&a: T, &&b: U, f: block(+a: T, +b: U) -> V) -> V { f(a, b) }
```

With which you could

```
vec::foldl(bind cp_ref2(_, _, uint_sub), 0, [1,2,3]);
```

If this is a good idea, then identify a bunch of useful scenarios and write these functions, maybe in std::util.