Haskell map / sortBy / findIndex etc. For arrays instead of lists

I see that it is possible to write functions like map / sortBy / findIndex and some other List related functions for arrays (at least indexed by integers). Is this done anywhere in the standard library, or do I need to roll on my own?

I need to use an array in my program to update in-place, but there are several places where I would like to use some of the list functions listed above. Does it translate between the best solution?

(The arrays I was looking at are related to Data.Array.IArray. I am also happy to use any other array library that implements this functionality.)

+5
source share
2 answers

I recommend you take a look at vector and vector-algorithms . They contain very efficient implementations of many common operations in Int-indexed arrays , both in mutable and immutable variants.

+5
source

fmap(of Control.Monad) looks like a generic version mapthat works on everything that supports a type class Functor. Arraysupports this, so you should be able to use fmapinstead mapfor an array.

As the hammar says, vector and vector algorithms are probably the best way to approach the problem if you need to consider indexed arrays.

+4
source

All Articles