使用ghcjs-dom将[Node]过滤为[Element]

时间:2016-08-01 22:44:37

标签: haskell dom ghcjs ghcjs-dom

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

import GHCJS.DOM.Types

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

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

1 个答案:

答案 0 :(得分: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