-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refactor] pull1Port: use partition
from Data.List
#62
Conversation
brat/Brat/Checker/Helpers.hs
Outdated
pull1Port p = do | ||
available <- get | ||
case partition ((== p) . toPort . fst) available of | ||
([], _) -> lift $ err $ BadPortPull $ "Port not found: " ++ p ++ " in " ++ showFn available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite a refactor (1/2): changed fail
to BadPortPull
as the latter is otherwise unused
brat/Brat/Checker/Helpers.hs
Outdated
case partition ((== p) . toPort . fst) available of | ||
([], _) -> lift $ err $ BadPortPull $ "Port not found: " ++ p ++ " in " ++ showFn available | ||
([found], remaining) -> put remaining >> pure found | ||
(_, _) -> lift $ err $ AmbiguousPortPull p (showFn available) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite a refactor (2/2): we used to pass to showFn
here only the suffix of available
beginning with the first match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this refactor is clearer than the original, save for the logic behind returning AmbiguousPortPull
. The rest is kind of obscured by the extra use of the state monad
eb2795d
to
e2983c7
Compare
Ok, fair enough, I think the main improvement here is the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, thanks!
partition
from Data.List
Not quite a refactor - change
fail
to aBadPortPull
error, and slight change to the error message for AmbiguousPortPull (now includes preceding but irrelevant/non-pulled ports)