[erlang-questions] max and min functions
James Hague
james.hague@REDACTED
Tue Dec 23 18:01:41 CET 2008
I've written helper functions to determine the max and min of two
values at least a dozen times now, so I'd like to propose they be
added to the standard libraries. lists:max/1 and list:min/1 give the
largest and smallest value in a list, but I'm talking about something
simpler:
max(1,10) ==> 10
min(1, 10) ==> 1
Along the same lines, I've also found myself writing "cap" (which caps
a value to be within two limits):
cap(5, 1, 10) ==> 5
cap(0, 1, 10) ==> 1
cap(20, 1, 10) ==> 10
cap(N, Low, High) is the same as min(max(N, Low), High). "limit" may
make more sense.
More information about the erlang-questions
mailing list