#Can you have function captures with multiple arguments?

1 messages · Page 1 of 1 (latest)

summer wren
#

let's say I have this piece of code:

fn do_something(a: Int, b: Int, c: String) {
  todo
}

let a = ...
list.index_map(bla, do_something(a, _, _))

So with index_map, you have get to arguments in the callback. Can I make that work with function captures?

crimson zenith
#

you can't do it with underscores (only one allowed)

#

you'll have to do list.index_map(bla, fn(b, c) { do_something(a, b, c) })

summer wren
#

yeah thought so, too bad

#

thanks

sharp oak
#

alternatively you could do something like this:

pub fn main() {
  let wibble = ["a", "b", "c"]
  let magic_number = 5

  wibble
  |> list.index_map(pair.new)
  |> list.map(do_something(magic_number, _))
}

fn do_something(a: Int, b: #(String, Int)) {
  io.debug(a)
  io.debug(b)
}