1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

📝 unprefixEither.

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

View File

@ -119,6 +119,9 @@ unprefix
-> (Stack a, t) -- ^ A stack of prefixing values & the final subterm.
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 from = go (0 :: Int) Nil
where go i bs t = case from i t of