summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndrey Listopadov <andreyorst@gmail.com>2021-02-22 19:43:18 +0300
committerAndrey Listopadov <andreyorst@gmail.com>2021-02-22 19:43:18 +0300
commit129a3a5d48f429de174faa6368e9625dcfb65f9e (patch)
treedb7e24509dd5a1b294c678f4f6bcd6ff3c9fd70d /doc
parente9b448d5fd3f074ee9de5066953c0becb891db19 (diff)
feat: add partition take and nthrest functions
Diffstat (limited to 'doc')
-rw-r--r--doc/cljlib.md72
-rw-r--r--doc/macros.md2
-rw-r--r--doc/tests/test.md2
3 files changed, 73 insertions, 3 deletions
diff --git a/doc/cljlib.md b/doc/cljlib.md
index 61765d4..a486bdf 100644
--- a/doc/cljlib.md
+++ b/doc/cljlib.md
@@ -101,6 +101,9 @@ non-ASCII strings.
- [`not-any?`](#not-any)
- [`range`](#range)
- [`reverse`](#reverse)
+- [`take`](#take)
+- [`nthrest`](#nthrest)
+- [`partition`](#partition)
- [`identity`](#identity)
- [`comp`](#comp)
- [`complement`](#complement)
@@ -904,6 +907,73 @@ Function signature:
Returns table with same items as in `tbl` but in reverse order.
+## `take`
+Function signature:
+
+```
+(take ([n col]))
+```
+
+Returns a sequence of the first `n` items in `col`, or all items if
+there are fewer than `n`.
+
+## `nthrest`
+Function signature:
+
+```
+(nthrest ([col n]))
+```
+
+Returns the nth rest of `col`, `col` when `n` is 0.
+
+### Examples
+
+``` fennel
+(assert-eq (nthrest [1 2 3 4] 3) [4])
+(assert-eq (nthrest [1 2 3 4] 2) [3 4])
+(assert-eq (nthrest [1 2 3 4] 1) [2 3 4])
+(assert-eq (nthrest [1 2 3 4] 0) [1 2 3 4])
+```
+
+## `partition`
+Function signature:
+
+```
+(partition ([n col]) ([n step col]) ([n step pad col]))
+```
+
+Returns a sequence of sequences 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 supplied, use its elements as
+necessary to complete last partition up to `n` items. In case there
+are not enough padding elements, return a partition with less than `n`
+items.
+
+### Examples
+Partition sequence into sub-sequences of size 3:
+
+``` fennel
+(assert-eq (partition 3 [1 2 3 4 5 6]) [[1 2 3] [4 5 6]])
+```
+
+When collection doesn't have enough elements, partition will not include those:
+
+``` fennel
+(assert-eq (partition 3 [1 2 3 4]) [[1 2 3]])
+```
+
+Partitions can overlap if step is supplied:
+
+``` fennel
+(assert-eq (partition 2 1 [1 2 3 4]) [[1 2] [2 3] [3 4]])
+```
+
+Additional padding can be used to supply insufficient elements:
+
+``` fennel
+(assert-eq (partition 3 3 [3 2 1] [1 2 3 4]) [[1 2 3] [4 3 2]])
+```
+
## `identity`
Function signature:
@@ -1188,5 +1258,5 @@ Copyright (C) 2020-2021 Andrey Listopadov
License: [MIT](https://gitlab.com/andreyorst/fennel-cljlib/-/raw/master/LICENSE)
-<!-- Generated with Fenneldoc 0.1.2
+<!-- Generated with Fenneldoc v0.1.3
https://gitlab.com/andreyorst/fenneldoc -->
diff --git a/doc/macros.md b/doc/macros.md
index d834c0a..e347e96 100644
--- a/doc/macros.md
+++ b/doc/macros.md
@@ -594,5 +594,5 @@ Copyright (C) 2020-2021 Andrey Listopadov
License: [MIT](https://gitlab.com/andreyorst/fennel-cljlib/-/raw/master/LICENSE)
-<!-- Generated with Fenneldoc 0.1.2
+<!-- Generated with Fenneldoc v0.1.3
https://gitlab.com/andreyorst/fenneldoc -->
diff --git a/doc/tests/test.md b/doc/tests/test.md
index 2f5f87a..cb97a81 100644
--- a/doc/tests/test.md
+++ b/doc/tests/test.md
@@ -93,5 +93,5 @@ Assert `expr` for not truth. Generates more verbose message if
`msg` is not set. Works the same as [`assert-is`](#assert-is).
-<!-- Generated with Fenneldoc 0.1.2
+<!-- Generated with Fenneldoc v0.1.3
https://gitlab.com/andreyorst/fenneldoc -->