Convert array to list in PureScript

Problem xy

How to convert an array to a list in PureScript?

arrayToList :: forall a. Array a -> List a arrayToList = ??? 

Actual problem

Do I have to write this function?

None of purescript-arrays and purescript-lists defines such a function, which makes me wonder if there is an idiomatic way to work with arrays in the context of functions that accept a list.

For example, Matrix.getRow returns an array that must be converted to a list of Pux Html elements (in the process of rendering the matrix as HTML). What is the best way to do this?

+8
arrays list purescript
source share
1 answer

With compiler version 0.10.2 you can just write

 arrayToList :: forall a. Array a -> List a arrayToList = ?whatGoesHere 

and the compiler will provide you with a list of things to populate based on type information. ?whatGoesHere is called a typed hole.

In this case, you probably want Data.Array.toUnfoldable or Data.List.fromFoldable .

+12
source share

All Articles