I'm stuck trying to refactor code below into one that would be reusable in different contexts. I would like to print another triple, for "parent" sub-tree but without explicitly passing lens to each textFrom
function.
Intuition tells me there should be a way to lift structure under Maybe (Text, Text, Text)
to one that takes an argument and passes it everywhere.
{-# LANGUAGE OverloadedStrings #-}
import System.Environment
import Text.XML.Lens
import Text.XML
import Data.String
import Control.Lens
import Control.Applicative
import Data.Maybe
import Data.Text
main = do
src:xs <- getArgs
pom <- load src
let textFrom name = listToMaybe $ pom ^.. root ./ ell name . text
coordinates = (,,) <$> textFrom "groupId" <*> textFrom "artifactId" <*> textFrom "version"
print $ coordinates -- pass (pom ^.. root) here
load = Text.XML.readFile def . fromString
parent pom = pom ^.. root ./ ell "parent"