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

mapMaybeM #183

Closed
andrewthad opened this issue Aug 29, 2017 · 8 comments · Fixed by #333
Closed

mapMaybeM #183

andrewthad opened this issue Aug 29, 2017 · 8 comments · Fixed by #333
Milestone

Comments

@andrewthad
Copy link
Contributor

Can I add mapMaybeM to vector? The type signature would be:

mapMaybeM :: (a -> m (Maybe b)) -> Vector a -> m (Vector b)

Although the list-equivalent of mapMaybeM is not in base, it's a pretty common thing for people to write. I can see from some googling that it exists in monad-extras, extra, and in stack. I bring this up because I think it highlights the utility of such a function and the common expected semantics people seem to have for it.

@cartazio
Copy link
Contributor

cartazio commented Aug 29, 2017 via email

@andrewthad
Copy link
Contributor Author

andrewthad commented Aug 29, 2017

I have. Still, a more direct definition of mapMaybeM would be more efficient that using witherM.

@cartazio
Copy link
Contributor

cartazio commented Aug 30, 2017 via email

@andrewthad
Copy link
Contributor Author

andrewthad commented Aug 30, 2017 via email

@Shimuuar
Copy link
Contributor

Also witherable instance couldn't be defined for both unboxed and storable vectors

@andrewthad
Copy link
Contributor Author

I just noticed the absence of these functions again when I was working on something. Is it alright for me to add these to vector?

@cartazio
Copy link
Contributor

cartazio commented Apr 5, 2018 via email

@andrewthad
Copy link
Contributor Author

What do you mean by a witherable-style interface? Currently, wither is defined as:

wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b)

What I'm proposing is:

mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Vector a -> m (Vector b)

My constraint is stronger, but my understanding is that vector's stream fusion only works with a Monad constraint. So, I don't think that the witherable interface can be supported.

treeowl added a commit to treeowl/vector that referenced this issue Nov 5, 2018
Add

```haskell
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Vector a -> m (Vector b)
imapMaybeM :: Monad m => (Int -> a -> m (Maybe b)) -> Vector a -> m (Vector b)
```

`mapMaybeM` is similar to `wither`, but the stream fusion framework
seems to require that we use a `Monad` constraint rather than an
`Applicative` one to get good performance. `imapMaybeM` is the
indexed variant.

Resolves haskell#183
@Shimuuar Shimuuar added this to the 0.13 milestone Jun 11, 2020
Shimuuar pushed a commit that referenced this issue Oct 10, 2020
Add

```haskell
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Vector a -> m (Vector b)
imapMaybeM :: Monad m => (Int -> a -> m (Maybe b)) -> Vector a -> m (Vector b)
```

`mapMaybeM` is similar to `wither`, but the stream fusion framework
seems to require that we use a `Monad` constraint rather than an
`Applicative` one to get good performance. `imapMaybeM` is the
indexed variant.

Resolves #183
lehins pushed a commit that referenced this issue Jan 16, 2021
Add

```haskell
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Vector a -> m (Vector b)
imapMaybeM :: Monad m => (Int -> a -> m (Maybe b)) -> Vector a -> m (Vector b)
```

`mapMaybeM` is similar to `wither`, but the stream fusion framework
seems to require that we use a `Monad` constraint rather than an
`Applicative` one to get good performance. `imapMaybeM` is the
indexed variant.

Resolves #183
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 a pull request may close this issue.

3 participants