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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to