diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index 6dd83b9..e6b5545 100644 --- a/src/tablecloth/column/api/column.clj +++ b/src/tablecloth/column/api/column.clj @@ -53,15 +53,18 @@ number, it is treated as an index from the end of the column. The `:start` and `:end` keywords can be used to represent the start and end of the column, respectively. + The `step` parameter determines the increment between each index in the + slice. It defaults to 1 if not provided. Examples: - (def column [1 2 3 4 5]) - (slice column 1 3) ;=> [2 3] - (slice column 2) ;=> [3 4 5] - (slice column -3 -1) ;=> [3 4 5] - (slice column :start 2) ;=> [1 2 3 4 5] - (slice column 2 :end) ;=> [3 4 5] - (slice column -2 :end) ;=> [4 5]" + (def c (column [1 2 3 4 5])) + (slice c 1 3) ;=> [2 3 4] + (slice c 2) ;=> [3 4 5] + (slice c -3 -1) ;=> [3 4 5] + (slice c :start 2) ;=> [1 2 3] + (slice c 2 :end) ;=> [3 4 5] + (slice c -2 :end) ;=> [4 5] + (slice c 0 :end 2) ;=> [1 3 5]" ([col from] (slice col from :end)) ([col from to] @@ -69,7 +72,7 @@ ([col from to step] (let [len (count col) from (or (when-not (or (= from :start) (nil? from)) from) 0) - to (or (when-not (or (= to :end) (nil? :end)) to) (dec len))] + to (or (when-not (or (= to :end) (nil? to)) to) (dec len))] (col/select col (range (if (neg? from) (+ len from) from) (inc (if (neg? to) (+ len to) to)) step)))))