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

Could I add average? #316

Closed
aleator opened this issue Aug 11, 2020 · 1 comment · Fixed by #318
Closed

Could I add average? #316

aleator opened this issue Aug 11, 2020 · 1 comment · Fixed by #318
Labels
extra Relude.Extra new Bring something new into library (add function or type or interface)

Comments

@aleator
Copy link
Contributor

aleator commented Aug 11, 2020

I find myself needing average perhaps more often than other people, but would it be ok to submit a patch to add either or both of these to relude:

average :: (Fractional a, Foldable f) => f a -> Maybe a

averageNonEmpty :: Fractional a => NonEmpty a -> a

A minor thing, but still a quality of life improvement in my opinion.

@vrom911 vrom911 added extra Relude.Extra new Bring something new into library (add function or type or interface) labels Aug 11, 2020
@vrom911
Copy link
Member

vrom911 commented Aug 11, 2020

Hey @aleator!
I see how it could be useful, luckily we already have Relude.Extra.Foldable and Relude.Extra.Foldable1 (for the NonEmpty option, we can call it average1 for consistency) where I think it is okay to add such functions.

aleator added a commit to aleator/relude that referenced this issue Aug 12, 2020
@chshersh chshersh added this to the v0.8.0.0: Standard milestone Aug 12, 2020
vrom911 pushed a commit that referenced this issue Aug 13, 2020
* Added `average` and `average1` functions

See #316.

* Fix the indentation

* ... Trailing newlines

* Update src/Relude/Extra/Foldable.hs

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>

* Documentation, explicit parameter order.

* Update src/Relude/Extra/Foldable.hs

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extra Relude.Extra new Bring something new into library (add function or type or interface)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants