score:0

Accepted answer

It will be easier to simply call max or min methods directly, rather than via a function. So instead of:

val input = IndexedSeq(1, 2, 3)

maxOrMin_1(input, (xs: IndexedSeq[Int]) => xs.max)
maxOrMin_1(input, (xs: IndexedSeq[Int]) => xs.min)

you just call directly:

input.max
input.min

If you still want the original function, you can make the calls more concise by currying (separate argument list for the input and for the function) which produces better type inference in Scala:

def maxOrMin_1(seq: IndexedSeq[Int])(maxMin: IndexedSeq[Int] => Int): Int = maxMin(seq)

then call as follows:

maxOrMin_1(input)(_.max)
maxOrMin_1(input)(_.min)

Related Query

More Query from same tag