1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

📝 the parameters to unprefixEither.

This commit is contained in:
Rob Rix 2019-08-06 12:05:22 -04:00
parent 7c686d1ccb
commit 0d2f05a8c7
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -122,7 +122,10 @@ unprefix from = unprefixEither (matchMaybe . from)
-- | Unwrap a (possibly-empty) prefix of @a@s wrapping a @b@ within a @t@ using a helper function.
--
-- Compared to 'unprefix', this allows the helper function to extract inner terms of a different type, for example when @t@ is a right @b@-module.
unprefixEither :: (Int -> t -> Either (a, t) b) -> t -> (Stack a, b)
unprefixEither
:: (Int -> t -> Either (a, t) b) -- ^ A function taking the 0-based index into the prefix & the current term, and returning either a pair of the prefixing value and the next inner subterm of type @t@, or the final inner subterm of type @b@.
-> t -- ^ The initial term.
-> (Stack a, b) -- ^ A stack of prefixing values & the final subterm.
unprefixEither from = go (0 :: Int) Nil
where go i bs t = case from i t of
Left (b, t) -> go (succ i) (bs :> b) t