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 function fmapNonNull #150

Closed
cdepillabout opened this issue Dec 13, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@cdepillabout
Copy link
Contributor

commented Dec 13, 2017

When I am working with NonNull in a new codebase, I often reimplement the following function:

fmapNonNull
  :: (Functor f, MonoFoldable (f b))
  => (a -> b) -> NonNull (f a) -> NonNull (f b)
fmapNonNull f = impureNonNull . fmap f . toNullable

This lets you call fmap on the underlying container in a NonNull. Here's an example:

> let nonNullable = impureNonNull [1,2,3] :: NonNull [Int]
> fmapNonNull show nonNullable :: NonNull [String]
["1","2","3"]

This is not possible with omap, because it does not let you change the type of the element in the underlying container.

I think this fmapNonNull would be widely useful, because NonNull is often used with Functors like [] or Seq.

This function could go into the Data.NonNull module.

Here are some possible names for this function:

  • fmapNonNull
  • fmapNonNullable
  • mapNonNull
  • mapNonNullable

I think any of those four names would be suitable.

If the maintainers agree that this could go into Data.NonNull, I will send a PR to include it.

@snoyberg

This comment has been minimized.

Copy link
Owner

commented Dec 14, 2017

@cdepillabout

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

Added in #151.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.