Reputation: 15882
I'm going crazy trying to use the simple >>.
and >.
functions defined here.
I want to get the length of all the text for a node in HXT. I'm using this:
runX (doc //> hasName "div" //> text >>. unlines)
Where doc
is my XmlTree
Arrow.
This gets me all the text for all divs (including text in any children they have). It gets the text as a string because I'm using unlines
. Now I want to get the length of that string, so I try:
runX (doc //> hasName "div" //> text >>. unlines >. length)
And HXT seems to magically convert my string back into an array, because I get this:
[0,17,0,20,0,11,...]
What I want is all those Int
s summed up. How would I do this?
Update:
The text function is defined like this:
text = deep (getChildren >>> getText)
I figured out that if I skip the getChildren
bit, this works correctly:
text = deep getText
As long as I only have one div
element. If I have multiple div
elements, I get back an array with the length for each element.
Upvotes: 3
Views: 251
Reputation: 13876
Consider the next two examples:
Prelude Text.XML.HXT.Core> flip runLA undefined $ (constL [1, 2] >>> arr id) >>. take 1
[1]
Prelude Text.XML.HXT.Core> flip runLA undefined $ constL [1, 2] >>> (arr id >>. take 1)
[1,2]
The difference is only in brackets. Without brackets it will work as the second example. So you have the issue cos different fixities.
Upvotes: 2