Core: Add isEven and isOdd to Basics

Created on 24 Aug 2015  路  9Comments  路  Source: elm/core

isEven is referenced on Basics docs, although the function is undefined. Both functions are used quite often, and they are tiny, so there's no trouble in adding them to Basics. Yes, the user can write (\x -> x%2==0), but isEven has little chance of name collision, used often and wouldn't require the user to write yet another small helper function.

Most helpful comment

I wrote elm-arithmetic, which includes isEven and isOdd, among a bunch of other useful functions.

All 9 comments

This is the policy on adding new stuff to core. I don't really believe the assertion that "Both functions are used quite often". To push this a bit further, can you come up with a list of languages and whether they have this? Like, for Python, Java, JavaScript, Ruby, OCaml, SML, Clojure, Scala, etc. do they have this imported by default? Or something else? If so, what is it?

FWIW, Clojure, Racket, Common Lisp and Emacs Lisp do import this or similar functions by default. I created this thread, because from meta-issue on API changes I understood I should create a new issue for any proposal for core that is somewhat viable. Other than that, I'm pretty happy to use *-extra packages.

What about the other languages I asked about? So far sounds like a lisp thing.

FWIW, I'm writing a little Arithmetic library with things like this in it, based loosely on Haskell's prelude + arithmoi. That sounds like a better place for things like this. (Is Arithmetic a good name, though?)

Yeah, that's the right way to go for now. Arithmetic sounds like a nice name to me :)

:+1: for having isEven and isOdd in Arithmetic. Also, there is a package math in Racket, which is very advanced and has all kinds of functions. If Arithmetic aspires to be anything like a general math-related library, it should be called math, I think.

To me, Math sounds like sin, cos, exp, ln... and Arithmetic sounds like isEven, isOdd, primes, gcd, lcm, Euclidean division... i.e., analysis vs. number theory. For some reason I feel like grouping them together would be messy, but maybe there's no reason not to?

(Also, some stuff got in the way, but I will continue work on the package soon. I'm basically translating arithmoi functions from Haskell to Elm to the best of my ability, which means it's quite involved, especially the prime stuff, but everything should be pretty fast!)

Just like there's Html, Html.Events, Html.Attributes, maybe there should be Math.Arithmetic, Math.Number (for number theory), Math.Trigonometry? Anyway, thanks for working on that :)

I wrote elm-arithmetic, which includes isEven and isOdd, among a bunch of other useful functions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

opvasger picture opvasger  路  6Comments

dullbananas picture dullbananas  路  3Comments

Fresheyeball picture Fresheyeball  路  8Comments

lorenzo picture lorenzo  路  5Comments

zzz6519003 picture zzz6519003  路  4Comments