我正在使用ghcjs-dom。如何从节点数组中过滤元素?
import GHCJS.DOM.Types
nodesToElements :: [Node] -> [Element]
nodesToElements = ??
或
nodesToElements :: [Node] -> IO [Element]
nodesToElements = ??
答案 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