From 8d140ccec8f68fd1fd4c7244570fcbff8663d361 Mon Sep 17 00:00:00 2001 From: Lin ZiHao Date: Sat, 31 Aug 2024 12:25:52 +0800 Subject: [PATCH] fix column slice function docstring --- src/tablecloth/column/api/column.clj | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index 15d3c5d..09030fc 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)))))