Skip to content

Add (%?) composition operator#434

Merged
arybczak merged 1 commit intowell-typed:masterfrom
matobet:master
Feb 26, 2022
Merged

Add (%?) composition operator#434
arybczak merged 1 commit intowell-typed:masterfrom
matobet:master

Conversation

@matobet
Copy link
Copy Markdown
Contributor

@matobet matobet commented Oct 4, 2021

o1 %? o2 = o1 % _Just % o2

Useful helper when "digging" through lot of Maybe fields, mirroring the usage of ?. operator from some object-oriented languages.

@arybczak
Copy link
Copy Markdown
Collaborator

I've found that this gets used quite a lot, I'm inclined to include it in the library. @adamgundry @phadej thoughts?

@arybczak
Copy link
Copy Markdown
Collaborator

arybczak commented Nov 1, 2021

@matobet please fix typos in the haddock.

@phadej
Copy link
Copy Markdown
Contributor

phadej commented Nov 1, 2021

I've found that this gets used quite a lot, I'm inclined to include it in the library. ... thoughts?

Fine with me. I'm not a fan of new operators in general, though.

I looked at a lens-heavy codebase and while somelens . _Just . otherlens is common, also lens . _Just and _Just . lens are also common, even cases like: p ^? _Just . oneRecordField . _Just, and there _Just would still persist.

I don't know whether I would remember to use %?, maybe if HLint warned.

o1 %? o2 = o1 % _Just % o2
@matobet
Copy link
Copy Markdown
Contributor Author

matobet commented Nov 2, 2021

@arybczak done. Hopefully caught them all

@arybczak arybczak merged commit 7eb2c7b into well-typed:master Feb 26, 2022
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.

3 participants