# Recommended 0.6 API for Dict-like constructors and functions

**URL:** <https://discourse.julialang.org/t/recommended-0-6-api-for-dict-like-constructors-and-functions/3743>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [May 16, 2017, 11:43am UTC](https://discourse.julialang.org/t/recommended-0-6-api-for-dict-like-constructors-and-functions/3743 "2017-05-16T11:43:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 16, 2017, 11:43am UTC](https://discourse.julialang.org/t/recommended-0-6-api-for-dict-like-constructors-and-functions/3743/1 "2017-05-16T11:43:44Z")

</div>

Suppose I have a function (usually, but not necessarily a constructor) with signature `myfun(xs...)` and I want it to be able to take a generator, eg `myfun(something(x) for x in itr)`. An example of this style in `Base` is `Dict`.

What is the recommended way of writing this in 0.6? The cheap way out is

```julia
myfun(xs::Base.Generator) = myfun(xs...)

```

but I don’t think that is optimal. Looking at [the source of `Base.Dict(kv)`](https://github.com/JuliaLang/julia/blob/master/base/dict.jl#L143), I see that first it tries `associative_with_eltype` and then fails with a nice error message if that is not applicable. So is `Base.associative_with_eltype` the way to go if I want similar functionality?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [May 16, 2017, 12:14pm UTC](https://discourse.julialang.org/t/recommended-0-6-api-for-dict-like-constructors-and-functions/3743/2 "2017-05-16T12:14:20Z")

</div>

Splatting is definitely not a good solution since it means the method needs to be recompiled for each number of elements in `xs`. I don’t know the specifics of your use case, but it would probably be better to define methods the other way around, with:

```julia
myfun(xs...) = myfun(xs)

```

The comparison with `Dict` doesn’t completely apply since it needs a generator of `Pair`. Unless that’s also your case, your requirements should be less strict: generally, you just need to be able to iterate over `itr`. In that case, `mean` is a better example.
