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