elm-community / array-extra

convenience functions for working with Array

Home Page:http://package.elm-lang.org/packages/elm-community/array-extra/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sorting

lue-bird opened this issue · comments

commented

I miss sorting operations like sort, sortBy & sortWith in List the most when working with arrays.
I think these would be worth adding to elm/core's Array module. Until anything gets decided, array-extra could just copy Lists sorting API:

sortWith : (a -> a -> Order) -> Array a -> Array a
sortWith elementOrder array =
    array
        |> Array.toList
        |> List.sortWith elementOrder
        |> Array.fromList

-- same with sort & sortBy

An example use-case is finding an Arrays 5 biggest numbers.