如何在 Purescript 中使用 mapWithIndex?

How to use mapWithIndex in Purescript?

我对 Purescript 很陌生,所以我在使用基于 Purescript 的框架之一时遇到了一个非常基本的问题。

我正在使用 PrestoDOM,我想知道如何使用 Data.Array 包中的 mapWithIndex 函数。 我试过如下,

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
  )
...

但是我得到了这个错误:

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

我知道这个错误直接来自于我对 mapWithIndex.

的错误使用

我终于可以解决问题了。 错误使用 mapWithIndex - 参数顺序。

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