Skip to content

[refactor] pullports again, with StateT + mapM#64

Merged
acl-cqc merged 1 commit intomainfrom
acl/refactor_pullports2
Dec 6, 2024
Merged

[refactor] pullports again, with StateT + mapM#64
acl-cqc merged 1 commit intomainfrom
acl/refactor_pullports2

Conversation

@acl-cqc
Copy link
Collaborator

@acl-cqc acl-cqc commented Dec 6, 2024

What's left of the earlier #62, reworked a bit.
StateT captures that we both pass the list of available things into pull1Port and then return the reduced version thereof; but rather than get, put and lift, using the StateT constructor and reordering the arguments.
Then mapM captures that each invocation of pull1Port returns a single thing that was pulled, or an error.

@acl-cqc acl-cqc requested a review from croyzor December 6, 2024 08:55
pull1Port p = StateT $ \available -> case partition ((== p) . toPort . fst) available of
([], _) -> err $ BadPortPull $ "Port not found: " ++ p ++ " in " ++ showFn available
([found], remaining) -> pure (found, remaining)
(_, _) -> err $ AmbiguousPortPull p (showFn available)
Copy link
Collaborator Author

@acl-cqc acl-cqc Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can imagine here (_, _) -> showFn available >>= err . AmbiguousPortPull p allowing showFn to use Checking i.e. showWithMetas in #54

@acl-cqc acl-cqc merged commit 05310cc into main Dec 6, 2024
@acl-cqc acl-cqc deleted the acl/refactor_pullports2 branch December 6, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants