Skip to content

Add (%?) composition operator - #434

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

arybczak merged 1 commit into
well-typed:masterfrom
matobet:master

Conversation

@matobet

@matobet matobet commented Oct 4, 2021

Copy link
Copy Markdown
Contributor
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

arybczak commented Nov 1, 2021

Copy link
Copy Markdown
Collaborator

@matobet please fix typos in the haddock.

@phadej

phadej commented Nov 1, 2021 •

Copy link
Copy Markdown
Contributor

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

matobet commented Nov 2, 2021

Copy link
Copy Markdown
Contributor Author

@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