0
votes

I'm a naive at Purescript, so I have a very basic issue while working with one of Purescript based frameworks.

I'm using PrestoDOM and I wonder how to use mapWithIndex function from Data.Array package. I tried like the following,

import Data.Array (mapWithIndex)
...
  (mapWithIndex
    (\(item index) ->  // want to use both item and its index through loop
      textView [
        width MATCH_PARENT
        , height WRAP_CONTENT
        , text item
        , visibility index > 0 ? VISIBLE : GONE
      ]
    )
    data
  )
...

but I got this error:

Unable to parse module:
  unexpected [
  expecting indentation at column 1 or end of input

I know this error directly comes from my wrong use of mapWithIndex.

1
It's not your wrong use of mapWithIndex, it's how you define the lambda expression: parameters cannot be in parentheses. Should be \item index -> ...Fyodor Soikin

1 Answers

0
votes

I could finally solve out the problem. Wrong use of mapWithIndex - parameter order.

(mapWithIndex
    (\index item ->
      textView [
        width MATCH_PARENT
        , height WRAP_CONTENT
        , text item
        , visibility index > 0 ? VISIBLE : GONE
      ]
    )
    data
  )