I lean on a soft no because we’d have to introduce six new functions as you
said, plus is_non_negative likely as well. To me, the comparison operator
is more clear and if you use it many many times, than nothing wrong with
writing down your own macros as you mentioned :).

On Sun, 19 Nov 2017 at 19:07, Isaac Whitfield <[email protected]> wrote:

> Hey all!
>
> Sorry if this has been broached previously, but searching didn't show
> anything (either on the list or on Google).
>
> I recently realised that I write a lot of `> 0` guard clauses, combined
> with the fact that they're either passing `is_integer/1` or `is_float/1`. I
> know that it's an easy thing to write yourself but:
>
> def my_function(value) when is_integer(value) and value > 0 do
>   # stuff
> end
>
> def my_function(value) when is_positive(value) do
>   # stuff
> end
>
> and based on the frequency I've used it, seems like a reasonable request
> for stdlib inclusion.
>
> So, I would like to propose the following (and feel free to shoot me
> down!). Of course each call would just be a macro:
>
> Integer.is_positive/1 - is_integer(val) and val > 0
> Integer.is_negative/1 - is_integer(val) and val < 0
> Float.is_positive/1   - is_float(val) and val > 0
> Float.is_negative/1   - is_float(val) and val < 0
> Kernel.is_positive/1  - is_number(val) and val > 0
> Kernel.is_negative/1  - is_number(val) and val < 0
>
> And coincidentally, I'm assuming that it's better to perform the type
> check first, I guess I'd appreciate if someone could confirm that? Also
> goes without saying that I'd be happy to impl this if we decide to adopt.
>
> Thanks for your consideration!
>
> IW
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/1d9f2250-9783-4af8-b2bb-9c0379f3b122%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/1d9f2250-9783-4af8-b2bb-9c0379f3b122%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 

Andrea Leopardi
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2B%2B5qxp41MOaL_fz_KCSa509sU7WShJMQuYgbi%3Dz6gu8zA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to