Clojure

partition docstring should be more explicit about dropped or partial trailing elements

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    OS X, 10.8
  • Patch:
    Code
  • Approval:
    Triaged

Description

The doc for partition states "In case there are not enough padding elements, return a partition with less than n items." However, the behavior of this function is as follows:

user=> (partition 3 (range 10))
((0 1 2) (3 4 5) (6 7 8))
user=> (partition 4 (range 10))
((0 1 2 3) (4 5 6 7))

Proposed: The docstring should be updated to make it clear that not providing a pad means that items are dropped, and to also see partition-all.

Patch: clj-1117.patch

Activity

Hide
Andy Fingerhut added a comment -

That would be a potentially breaking change for some people's code that uses partition. partition-all behaves as you wish.

Also, your concern with the documentation is for when there are padding elements specified as an argument, but your examples don't specify any padding elements.

Show
Andy Fingerhut added a comment - That would be a potentially breaking change for some people's code that uses partition. partition-all behaves as you wish. Also, your concern with the documentation is for when there are padding elements specified as an argument, but your examples don't specify any padding elements.
Hide
Timothy Baldridge added a comment -

I agree, but I think the docs should then explicitly state: "if no padding is given, not all input elements may be returned in the output partitions" or something to that line.

Show
Timothy Baldridge added a comment - I agree, but I think the docs should then explicitly state: "if no padding is given, not all input elements may be returned in the output partitions" or something to that line.
Hide
Andy Fingerhut added a comment -

More precise documentation of current behavior is always welcome in my opinion.

Show
Andy Fingerhut added a comment - More precise documentation of current behavior is always welcome in my opinion.
Hide
Gabriel Horner added a comment -

I've uploaded a patch that calls out when and how partition drops tail elements:
"If a pad collection is not supplied, any tail elements that remain from dividing the input collection length by n will not be included in a partition."

Show
Gabriel Horner added a comment - I've uploaded a patch that calls out when and how partition drops tail elements: "If a pad collection is not supplied, any tail elements that remain from dividing the input collection length by n will not be included in a partition."

People

Vote (5)
Watch (2)

Dates

  • Created:
    Updated: