# Could the usage of \`haskey\` be unidiomatic/inefficient?

**URL:** <https://discourse.julialang.org/t/could-the-usage-of-haskey-be-unidiomatic-inefficient/17442>\
**Category:** Performance\
**Tags:** dictionary\
**Created:** [November 12, 2018, 6:00pm UTC](https://discourse.julialang.org/t/could-the-usage-of-haskey-be-unidiomatic-inefficient/17442 "2018-11-12T18:00:56Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [November 12, 2018, 6:28pm UTC](https://discourse.julialang.org/t/could-the-usage-of-haskey-be-unidiomatic-inefficient/17442/3 "2018-11-12T18:28:22Z")

</div>

What about

```julia
function dostuff(dict, key)
    found = true
    item = get(() -> found = false, dict, key)
    if found
        Some(item)
    else
        nothing
    end
end

d = Dict([1 => 'a'])
dostuff(d, 1) # Some('a')
dostuff(d, 2) # nothing

```

---

_[View the full topic](https://discourse.julialang.org/t/could-the-usage-of-haskey-be-unidiomatic-inefficient/17442)._
