I tried to get all top-level assignments and ended up with:
extractAssignments :: List -> [Assign]
extractAssignments (List stms) = join $ fmap getAssign $ getCommands stms
where
getCommands :: [Statement] -> [Command]
getCommands = join . fmap commands . catMaybes . fmap findPipes
where
findPipes (Statement (Last p@(Pipeline{})) Sequential) = Just p
findPipes _ = Nothing
getAssign :: Command -> [Assign]
getAssign (Command (SimpleCommand ass _) _) = ass
getAssign _ = []
I believe this would be easier with optics. I would propose the optics package, because it has better documentation, an opaque interface with useful type errors and safer behavior in some corner cases (e.g. less implicit monoidal behavior) than lens.
I tried to get all top-level assignments and ended up with:
I believe this would be easier with optics. I would propose the optics package, because it has better documentation, an opaque interface with useful type errors and safer behavior in some corner cases (e.g. less implicit monoidal behavior) than lens.