Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Created October 12, 2022 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/3b1e7a2f5eab7055e7438f8dd5da7f1f to your computer and use it in GitHub Desktop.
Save dminuoso/3b1e7a2f5eab7055e7438f8dd5da7f1f to your computer and use it in GitHub Desktop.
lookupDel :: (Eq a) => a -> [(a,b)] -> (b -> [(a, b)] -> t) -> t -> t
lookupDel key as just nothing = go as []
where
go ((x,y):xys) ss
| key == x = just y (ss <> xys)
| otherwise = go xys ((x,y) : ss)
go [] ss = nothing
workMembers :: [IT.TextTree ASpec] -> [(T.Text, Attr)] -> [(Attr, IT.TextTree ASpec)] -> ExM [EncodableAttr]
workMembers (m:ms) req es = let aspec = IT.rootValue m
member = asNam aspec
in lookupDel member req (\n req' -> workMembers ms req' ((n, m):es))
(workMembers ms req es)
workMembers [] req@(_:_) es = abort (EE_MissingMembers (attrNam [nam]) (fst <$> req))
workMembers ms@(_:_) [] es = abort (EE_ExtraMembers (attrNam [nam]) (asNam . IT.rootValue <$> ms))
workMembers [] [] es = traverse (\(attr, subtree') ->
go (p `dlistSnoc` nam) subtree' attr
) es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment