I would prefer to write the factorial method like this
That is what the ?: operator was designed for, and avoids a double
return. It is worth adding Exceptions if the argument is too big (I forget, but I think 22! is the largest factorial which will fit into a
long) or negative.
It is worth remembering what a function is: it returns one result, and really ought always to return the same result for the same input. Factorial, sine, logarithm, square, etc are functions. So is a phone book (or rather was, in the days before people carried several mobiles, and only had one phone number each
), and you can easily represent a phone book as a
Map. That is why that link says
A Map . . . models the mathematical function abstraction. Their italics.