Skip to content
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

Add mapMaybe for Trie #16

Merged
merged 7 commits into from Dec 1, 2020
Merged

Add mapMaybe for Trie #16

merged 7 commits into from Dec 1, 2020

Conversation

z0isch
Copy link
Contributor

@z0isch z0isch commented Dec 1, 2020

I needed a mapMaybe like function over Trie a when trying to write a function to union two Tries with some default behavior in text-assets

This implements mapMaybe but with a slight wrinkle in that you ultimately must return a Maybe (Trie a) due to the fact that Trie a should be non-empty.

@z0isch z0isch self-assigned this Dec 1, 2020
@z0isch z0isch requested a review from eborden December 1, 2020 20:10
z0isch and others added 2 commits December 1, 2020 15:13
Co-authored-by: Restyled.io <commits@restyled.io>
bcp47/tests/Data/BCP47/TrieSpec.hs Outdated Show resolved Hide resolved
bcp47/library/Data/BCP47/Trie/Internal.hs Show resolved Hide resolved
@z0isch z0isch requested a review from eborden December 1, 2020 20:40
Comment on lines +75 to +76
mapMaybe :: (a -> Maybe b) -> Trie a -> Maybe (Trie b)
mapMaybe f (Trie x) = Trie <$> nullToMaybe (Map.mapMaybe (mapMaybe2 f) x)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to get a quick check invariant for this.

Copy link
Contributor Author

@z0isch z0isch Dec 1, 2020

Choose a reason for hiding this comment

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

Good idea- I added one for making sure that we have the same Justs before and after

Co-authored-by: Restyled.io <commits@restyled.io>
@z0isch z0isch requested a review from eborden December 1, 2020 21:10
@z0isch z0isch merged commit 00266e8 into master Dec 1, 2020
@z0isch z0isch deleted the aj/mapMaybe branch December 1, 2020 21:37
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.

None yet

2 participants