Skip to content

Conversation

@mgkuhn
Copy link
Contributor

@mgkuhn mgkuhn commented Jan 13, 2019

A new optional keyword argument kwargs can now take a named tuple and Base.sprint will then pass on the content of that named tuple as keyword arguments to the function called.

A new optional keyword argument `kwargs` can now take a named tuple
and Base.sprint will then pass on the content of that tuple as
keyword arguments to the function called.
@StefanKarpinski
Copy link
Member

Wouldn't it generally be clearer to pass a closure for this kind of usage?

@mgkuhn
Copy link
Contributor Author

mgkuhn commented Jan 13, 2019

Ah, thanks for the hint, I hadn't thought of that. Slightly slower, but not much:

using BenchmarkTools
wrap(io, strings...; open='(', close=')') = print(io, open, strings..., close)
a = 'a'
@btime sprint(wrap, a...; kwargs = (open='[',))
@btime sprint((s...) -> wrap(s...; open='['), a...)
@btime sprint((s...) -> wrap(s...), a...)
@btime sprint(wrap, a...)

gives

  683.224 ns (10 allocations: 448 bytes)
  1.035 μs (8 allocations: 368 bytes)
  662.226 ns (6 allocations: 320 bytes)
  598.449 ns (6 allocations: 320 bytes)

@kshyatt kshyatt added the strings "Strings!" label Jan 13, 2019
@mgkuhn mgkuhn closed this Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

strings "Strings!"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants