haquery icon indicating copy to clipboard operation
haquery copied to clipboard

select should accept [Tag]

Open domenkozar opened this issue 9 years ago • 4 comments

I'd propose to give a following example of using Haquery in ghci, which is one of the common usages of fetching a website and parsing it.

import Haquery (select, parseHtml)
import Network.Wreq (get, responseBody)
import Control.Lens (^.)
import Data.Text (pack)

r <- get "http://nixos.org/channels/"
Prelude.concatMap (select (pack "a")) $ parseHtml $ pack $ show (r ^. responseBody)

Which motivates me to say that select should accept a list of Tags, since that's what parseHtml returns.

PS: I'm fairly new to Haskell ecosystem, so excuse my ignorance :)

domenkozar avatar Oct 15 '16 09:10 domenkozar

Another strong reason is that the returned [Tag] can be then chained to subsequent select calls.

domenkozar avatar Oct 15 '16 09:10 domenkozar

Yes, I think I'd also like this change. Any reason to the contrary, @crufter?

Wizek avatar Mar 09 '17 15:03 Wizek

Just occured to me that we could also define

selects :: Text -> [Tag] -> [Tag]
selects sel tags = concat $ map (select sel) tags

Wizek avatar Mar 09 '17 16:03 Wizek

@Wizek I will implement that

crufter avatar Mar 09 '17 16:03 crufter