From ef174741a260365780fb4cd20ef7bcbb3cd91189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Fr=C4=85cek?= Date: Thu, 12 Dec 2024 23:13:54 +0100 Subject: [PATCH] updated readme --- README.md | 25 +++++++++++++++++++++++-- docs/index.md | 26 ++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c6b044..c2e7998 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,24 @@ merged_list = QList([1, 2, 5, 7, 8]).merge([3, 4, 6, 9], lambda left, right: lef # [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` -### "Pure" functional style -Qwery List offers methods such as `fold` and `uncons` that are well known from functional languages. +### Grouping capabilities +Query List offers a bunch of grouping capabilities such as `window`, `batch`, `batch_by`, `group_by`. +```python +QList([1, 2, 3, 4, 5]).window(2).collect() +# [[1, 2], [2, 3], [3, 4], [4, 5]] + +QList([1, 2, 3, 4, 5]).batch(2).collect() +# [[1, 2], [3, 4], [5]] + +QList(['a1', 'b1', 'b2', 'a2', 'a3', 'b3']).batch_by(lambda s: s[0]).collect() +# [['a1'], ['b1', 'b2'], ['a2', 'a3'], ['b3']] + +QList(['a1', 'b1', 'b2', 'a2', 'a3', 'b3']).group_by(lambda s: s[0]).collect() +# [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] +``` + +### Pure functional style +Qwery List offers methods such as `fold`, `flat_fold` and `uncons` that are well known from functional languages. ```python head, tail = Lazy([1, 2, 3, 4]).uncons() # head = 1 @@ -136,6 +152,11 @@ data = values.fold(lambda acc, x: update_dict(acc, *x), {}) # {'name': ['Alex', 'David'], 'country': ['Poland']} ``` + +```python +QList([2, 3]).flat_fold(lambda acc, x: [acc + x, acc * x], 1).collect() +# [6, 9, 5, 6] +``` --- # Installation diff --git a/docs/index.md b/docs/index.md index 0088574..d6bf23b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -111,8 +111,24 @@ merged_list = QList([1, 2, 5, 7, 8]).merge([3, 4, 6, 9], lambda left, right: lef # [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` -### "Pure" functional style -Qwery List offers methods such as `fold` and `uncons` that are well known from functional languages. +### Grouping capabilities +Query List offers a bunch of grouping capabilities such as `window`, `batch`, `batch_by`, `group_by`. +```python +QList([1, 2, 3, 4, 5]).window(2).collect() +# [[1, 2], [2, 3], [3, 4], [4, 5]] + +QList([1, 2, 3, 4, 5]).batch(2).collect() +# [[1, 2], [3, 4], [5]] + +QList(['a1', 'b1', 'b2', 'a2', 'a3', 'b3']).batch_by(lambda s: s[0]).collect() +# [['a1'], ['b1', 'b2'], ['a2', 'a3'], ['b3']] + +QList(['a1', 'b1', 'b2', 'a2', 'a3', 'b3']).group_by(lambda s: s[0]).collect() +# [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] +``` + +### Pure functional style +Qwery List offers methods such as `fold`, `flat_fold` and `uncons` that are well known from functional languages. ```python head, tail = Lazy([1, 2, 3, 4]).uncons() # head = 1 @@ -136,6 +152,12 @@ data = values.fold(lambda acc, x: update_dict(acc, *x), {}) # {'name': ['Alex', 'David'], 'country': ['Poland']} ``` + +```python +QList([2, 3]).flat_fold(lambda acc, x: [acc + x, acc * x], 1).collect() +# [6, 9, 5, 6] +``` + --- # Installation