如何在Purescript中使用mapWithIndex?

问题描述 投票:0回答:1

我是Purescript的幼稚者,因此在使用基于Purescript的框架之一时遇到一个非常基本的问题。

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

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的错误使用。

purescript
1个回答
0
投票

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

(mapWithIndex
    (\index item ->
      textView [
        width MATCH_PARENT
        , height WRAP_CONTENT
        , text item
        , visibility index > 0 ? VISIBLE : GONE
      ]
    )
    data
  )
© www.soinside.com 2019 - 2024. All rights reserved.