[Steven D'Aprano <st...@pearwood.info>] wrote:
>>>     values = take(count, items, default=None)

[MRAB]
>> Why is the count first? Why not have the (definitely required) items
>> first and let the count have a default of 1?

[Steven]
> I lifted the bulk of the function, including the signature, from the
> recipe in the itertools documentation.
>
> I suspect the reason the recipe specifies the count first is because
> that follows the standard order in English:
>
> "take two of the eggs"
>
> rather than "take eggs two of".

Part of it, but I believe it's more following prior art, like Haskell's take:

http://zvon.org/other/haskell/Outputprelude/take_f.html

In that language, the case for putting the count first is
overwhelming:  all functions in Haskell take a single argument, and
currying is ubiquitous.

Being able, e.g., to write

take3 = take 3

to get a function that returns the first 3 elements of whatever that
function is applied to is far more useful, e.g., than being able to
write

take_from_x = take x

to get a function such that `take_from_x n` returns the first `n`
elements of `x`.

The same follows in a weaker way in Python via fans of functools.partial
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CBML55NJXZLVUMLFYF5SRWSTA7MI2SCE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to