1

I have the following lines of code:

f((k,v)) = Symbol(k) => Symbol(v)
Dict(Iterators.map(f, pairs(names)))

And I want to write it in a single line. I tried this:

Dict(Iterators.map((k,v) -> Symbol(k) => Symbol(v), pairs(names)))

But it throws Method Error:

MethodError: no method matching (::var"#13#14")(::Pair{Symbol, String})

Is it possible to write this in a single line?

Jafar Isbarov
  • 1,363
  • 1
  • 8
  • 26

2 Answers2

4

What about

Dict(Symbol(k)=>Symbol(v) for (k, v) in pairs(names))

?

DNF
  • 11,584
  • 1
  • 26
  • 40
3

You want this:

Dict(Iterators.map(((k,v),) -> Symbol(k) => Symbol(v), pairs(names)))

(note the comma after (k,v) which forces destruction of the first argument to the anonymous function into two eleements)

Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107