0

我正在使用 ghcjs-dom。如何从节点数组中过滤元素?

import GHCJS.DOM.Types

nodesToElements :: [Node] -> [Element]
nodesToElements = ??

或者

nodesToElements :: [Node] -> IO [Element]
nodesToElements = ??
4

1 回答 1

1
import GHCJS.DOM.Types
import Data.Maybe (mapMaybe)

nodeToElement :: Node -> Maybe Element
nodeToElement node = if node `isA` gTypeElement
                     then Just $ castToElement node
                     else Nothing

nodesToElements :: [Node] -> [Element]
nodesToElements = mapMaybe nodeToElement
于 2016-08-02T01:54:41.000 回答