# Defining in(a,b)

**URL:** <https://discourse.julialang.org/t/defining-in-a-b/4134>\
**Category:** General Usage\
**Created:** [June 7, 2017, 11:07am UTC](https://discourse.julialang.org/t/defining-in-a-b/4134 "2017-06-07T11:07:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 7, 2017, 11:07am UTC](https://discourse.julialang.org/t/defining-in-a-b/4134/1 "2017-06-07T11:07:19Z")

</div>

Is in(a,b) defined automatically by making b iterable and defining ==(a1::T, a2::T) where T is typeof(a) and typeof(b[i])?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 7, 2017, 11:21am UTC](https://discourse.julialang.org/t/defining-in-a-b/4134/2 "2017-06-07T11:21:54Z")

</div>

`in` is defined as `in(x, itr) = any(y -> y == x, itr)`

`any` is defined as

```julia
function any(f, itr)
    for x in itr
        f(x) && return true
    end
    return false
end

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 7, 2017, 12:22pm UTC](https://discourse.julialang.org/t/defining-in-a-b/4134/3 "2017-06-07T12:22:39Z")

</div>

I think it would be handy if a dependency tree of all these Base functions often overloaded was documented.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 7, 2017, 12:32pm UTC](https://discourse.julialang.org/t/defining-in-a-b/4134/4 "2017-06-07T12:32:14Z")

</div>

Perhaps, the documentation is pretty good here though imo:

> Determine whether an item is in the given collection, in the sense that it  
> is == to one of the values generated by iterating over the collection.
