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:
    Prescreened

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: Proposed docstring update in bold:

Returns a lazy sequence of lists of n items each, at offsets step
apart. If step is not supplied, defaults to n, i.e. the partitions
do not overlap. **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.** If a pad collection is supplied, use its elements as
necessary to complete last partition upto n items. In case there are
not enough padding elements, return a partition with less than n items.

Patch: clj-1117.patch

Activity

Gabriel Horner made changes -
Field Original Value New Value
Patch Code [ 10001 ]
Affects Version/s Release 1.4 [ 10040 ]
Affects Version/s Release 1.6 [ 10157 ]
Attachment clj-1117.patch [ 11994 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
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))
user=> (partition 5 (range 10))
((0 1 2 3 4) (5 6 7 8 9))

Either the doc should be updated to make it clear that not providing a pad will mean that items are dropped, or the functionality of partition should be fixed to the following:

user=> (partition 3 (range 10))
((0 1 2) (3 4 5) (6 7 8) (9))
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:

{code}
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))
{code}

*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
Labels docstring
Alex Miller made changes -
Issue Type Defect [ 1 ] Enhancement [ 4 ]
Summary Partition does not follow docs partition docstring should be more explicit about dropped or partial trailing elements
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Priority Major [ 3 ] Minor [ 4 ]
Alex Miller made changes -
Approval Triaged [ 10120 ] Prescreened [ 10220 ]
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:

{code}
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))
{code}

*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
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:

{code}
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))
{code}

*Proposed:* Proposed docstring update *in bold*:

Returns a lazy sequence of lists of n items each, at offsets step
apart. If step is not supplied, defaults to n, i.e. the partitions
do not overlap. **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.** If a pad collection is supplied, use its elements as
necessary to complete last partition upto n items. In case there are
not enough padding elements, return a partition with less than n items.

*Patch:* clj-1117.patch

People

Vote (6)
Watch (3)

Dates

  • Created:
    Updated: