I needed to call this function `takeNsmallest`

on a `List`

and also on a `MapView`

. So I duplicated the function and only changed the type declarations.

Is there a better way in this case? Should I write the function once and just use cleverer declarations?

```
def takeNsmallest[T](n: Int, data: List[T], measure: T => Double): List[T] = {
if (n == 0 || data.isEmpty)
List()
else {
data
.foldLeft(MaxSizeList[T](n, measure, List[T]())) { (acc, next) => MaxSizeList(n, measure, next :: acc.items) }
.items
}.sortBy(measure)
}
def takeNsmallest[A,B](n: Int, data: MapView[A,B], measure: ((A,B)) => Double): List[(A,B)] = {
if (n == 0 || data.isEmpty)
List()
else {
data
.foldLeft(MaxSizeList[(A,B)](n, measure, List[(A,B)]())) { (acc, next) => MaxSizeList(n, measure, next :: acc.items) }
.items
}.sortBy(measure)
}
```