# Looping over different types with common behavior

**URL:** <https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068>\
**Category:** Performance\
**Created:** [June 29, 2018, 3:22pm UTC](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068 "2018-06-29T15:22:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [June 29, 2018, 6:13pm UTC](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068/5 "2018-06-29T18:13:46Z")

</div>

You could also use [TypeSortedCollections.jl](https://github.com/tkoolen/TypeSortedCollections.jl) for this (I’m the author). It basically automates your `createconcretecollection`/`sumconcretecollection` approach:

```julia
julia> using TypeSortedCollections

julia> tsc = TypeSortedCollection(createabstractcollection());

julia> @btime mapreduce(value, +, 0, $tsc)
  1.204 ms (0 allocations: 0 bytes)
500001499788

```

---

_[View the full topic](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068)._
