Skip to content

Refactor [] to NonEmpty in Quasi module#1193

Merged
parsonsmatt merged 6 commits intoyesodweb:masterfrom
danbroooks:refactor-to-non-empty
Mar 15, 2021
Merged

Refactor [] to NonEmpty in Quasi module#1193
parsonsmatt merged 6 commits intoyesodweb:masterfrom
danbroooks:refactor-to-non-empty

Conversation

@danbroooks
Copy link
Contributor

A refactoring contribution towards #1061

@danbroooks danbroooks changed the title Refactor to non empty Refactor [] to NonEmpty in Quasi module Feb 24, 2021
@parsonsmatt
Copy link
Collaborator

I've fixed CI, mind rebasing and trying again?

parse ps = maybe [] (parseLines ps) . preparse

preparse :: Text -> [Line]
preparse :: Text -> Maybe (NonEmpty Line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe (NonEmpty a) is equivalent to [a]. What's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well its just so that parseLines can take a NonEmpty value, but it might make sense to make that call to nonEmpty within parse actually and then leave preparse alone.

I guess alternatively though you could say preparse can potentially fail to return anything of interest, and thus that is represented as a Nothing value here. You can say the same thing about parse as well, though obviously that needs to remain as [].

I'm happy to move nonEmpty directly into parse though if that makes more sense 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'm just not sure about the benefit of this particular [] -> NonEmpty change. We don't appear to have any behavior that assumes or depends on [] being non-empty somewhere with this set of code.

But, it's also not a breaking change, and it seems like it makes sense semantically in the parsing section here.

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

Thanks! 😄

parse ps = maybe [] (parseLines ps) . preparse

preparse :: Text -> [Line]
preparse :: Text -> Maybe (NonEmpty Line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'm just not sure about the benefit of this particular [] -> NonEmpty change. We don't appear to have any behavior that assumes or depends on [] being non-empty somewhere with this set of code.

But, it's also not a breaking change, and it seems like it makes sense semantically in the parsing section here.

@parsonsmatt
Copy link
Collaborator

Since this is a refactoring-only change, isn't exposed to the public interface, and is covered entirely by the tests, I'm going to merge without requiring a changelong entry.

If you want to put a changelog entry in for the sweet sweet credit, feel free to push it up. I'll merge this sometime in the next few days.

Thanks!

@parsonsmatt parsonsmatt merged commit fdd7b7b into yesodweb:master Mar 15, 2021
@danbroooks danbroooks deleted the refactor-to-non-empty branch April 22, 2021 10:45
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