# Is it possible to integrate the similar functions into one?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576
**Category:** General Usage
**Tags:** question
**Created:** [November 1, 2019, 8:09am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576 "2019-11-01T08:09:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Yan](https://avatars.discourse-cdn.com/v4/letter/y/3e96dc/32.png) [@Yan](https://discourse.julialang.org/u/Yan)
#### Post date: [November 1, 2019, 8:09am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/1 "2019-11-01T08:09:47Z")

</div>

Is it possible to integrate the similar functions into one, by expending its abilities.  
For instance: max; maximum; findmax.

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [November 1, 2019, 8:25am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/2 "2019-11-01T08:25:54Z")

</div>

can you give an example of your desired syntax?

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [November 1, 2019, 9:21am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/3 "2019-11-01T09:21:08Z")

</div>

These functions all have different use cases - `max` returns the maximum of its arguments, `findmax` returns the index of the maximal element in the given collection and `maximum` returns the maximal element itself. While it could be argued that `max` and `maximum` can be merged, `findmax` serves a different purpose and should imo stay separate. Additionally, the `maximum` function allows for a function to be called on each element of the given collection before reducing.

---

<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 1, 2019, 9:45am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/4 "2019-11-01T09:45:11Z")

</div>

A generalization I could think of is allowing an arbitrary comparison operator for `findmax` & friends instead of the hardcoded `isless`. Then `findmin` just amounts to using `!isless`, etc.

Cf

[https://github.com/JuliaLang/julia/issues/14216](https://github.com/JuliaLang/julia/issues/14216)

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [November 1, 2019, 9:59am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/5 "2019-11-01T09:59:09Z")

</div>

> [@Sukera](#):
>
> While it could be argued that `max` and `maximum` can be merged

I don’t know about merging but personally I always found that the current `maximum` should be named `max` (for example switch the two names). My feeling is that people (surely me) are using `maximum` much more often than `max`, so it’s a bit annoying that the long version has to be typed more often. Also, while not a particularily strong argument, in other PLs `max` is often Julia’s `maximum`.

---

<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 1, 2019, 10:06am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/6 "2019-11-01T10:06:35Z")

</div>

Cf

[https://github.com/JuliaLang/julia/issues/4652](https://github.com/JuliaLang/julia/issues/4652)

and the detailed explanation in the referenced discussion

[https://github.com/JuliaLang/julia/issues/4235](https://github.com/JuliaLang/julia/issues/4235)

---

<div class="post-metadata">

### Author: ![Yan](https://avatars.discourse-cdn.com/v4/letter/y/3e96dc/32.png) [@Yan](https://discourse.julialang.org/u/Yan)
#### Post date: [November 1, 2019, 10:45am UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/8 "2019-11-01T10:45:57Z")

</div>

Yes, they are different, due to acting on different data structures.

It seems both maximum and findmax targeting the same data structure?  
If that, can it be using maximum(a, dims=1, position=true) instead of findmax?

---

<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 1, 2019, 12:00pm UTC](https://discourse.julialang.org/t/is-it-possible-to-integrate-the-similar-functions-into-one/30576/9 "2019-11-01T12:00:35Z")

</div>

Theoretically yes — the compiler is now smart enough (I think) to do the constant folding, so in general any two functions can be combined into a single one:

```julia
f(args...) = "something"
g(args...) = "something else"
fg(args...; do_f = true) = do_f ? f(args...) : g(args...)

```

So sure, it is possible, but it may not be a proposal that would gather wide support, as `findmax` and `maximum` share neither their purpose nor their implementation.
