I am trying to parse XML, but I want to filter and retrieve only a certain number of children from a given node. For instance:
<root> <node id="a" /> <node id="b" /> <node id="c" /> <node id="d" /> </root>
And then, if I getChildren >>> myFilter 2 arrow, I will only return nodes with identifiers "a" and "b".
Intuition suggests that I should use the status arrow to track, but I donβt know how to do this.
I tried to do it myself, but this is not quite what I want, it does not look very elegant and does not work. I am trying to start my arrow chain with runSLA and an integer parameter as the initial state, and then determine:
takeOnly :: IOSLA Int XmlTree XmlTree takeOnly = changeState (\sb -> s-1) >>> accessState (\sb -> if s >= 0 then b else Nothing)
But of course, I cannot return Nothing , I need to return XmlTree. But I donβt want to return anything at all!
There is probably a better way out. Can you help me?
Thanks for your time and help!
haskell state arrows hxt
Jorge diz
source share