Last active
November 19, 2016 07:49
-
-
Save expipiplus1/19f5bd88a81bdf9abcab50fce34197c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data UpdateSource = VersionSet{ versionExpr :: NExprLoc | |
, sources :: [UpdateSource] | |
} | |
| FetchGit{ args :: FetchGitArgs | |
, sources :: [UpdateSource] | |
} | |
-- This is the 'para' function from the 'recursion-schemes' package | |
-- I've made the type signature specific to NixExprLoc | |
para :: (NixExprLocF (NixExprLoc, a) -> a) -> NixExprLoc -> a | |
f :: NExprLocF (NExprLoc, [UpdateSource]) -> [UpdateSource] | |
f e = let -- Get all the sub-sources for this expression | |
-- This expression has for its subexpressions tuples of type | |
-- (NixExprLoc, [UpdateSource]). The first element of this tuple is | |
-- the actual subexpression, the second element is the list of | |
-- 'UpdateSource's calculated by 'para' further down the tree. | |
-- | |
-- first convert this expression to a list of type | |
-- [(NExprLoc, [UpdateSource])] using 'toList' from the 'Foldable' | |
-- type class. Then map 'snd' over each element to get the list of | |
-- type [UpdateSource] for each element. Finally concatenate all | |
-- these lists into one larger list with elements of type | |
-- UpdateSource | |
subs = concat . map snd . toList $ e | |
in case e of | |
-- If this is a call to 'fetchgit' then extract the arguments | |
CallToFetchGit -> [FetchGit{ args = extractFetchGitArgs (fst <$> e) | |
, sources = subs | |
}] | |
-- If this is an attr set with a version attribute, remember where | |
-- the version attribute was and set the sub sources | |
AttrSetWithVersion -> [VersionSet{ versionExpr = extractVersionAttr | |
, sources = subs | |
}] | |
-- If this is something else, just forward the sub sources | |
_somethingUninteresting -> subs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment