On Dec 9, 2019, at 17:16, Tim Peters <tim.pet...@gmail.com> wrote:
> 
> [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`.

But also, the decision isn’t as important in Haskell, because you can always 
flip take and then curry that. So you can just follow the convention everywhere 
without worrying about whether this is one of the rare cases where the other 
way around might actually be useful more often.

_______________________________________________
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/2TEUN4AKYCA5W37M4LR7V4PLIB4IFTJV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to