From 985bda1b5a1cd588a429b52bddab5406796c7736 Mon Sep 17 00:00:00 2001 From: Kian Kasad Date: Mon, 13 May 2024 12:51:06 -0700 Subject: [PATCH] Add once iterator --- README.md | 1 + src/repeat.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index c135c89..15fc3a6 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ All iterators and functions below are prefixed with the name `citer_` to avoid c | flatten | Flattens an iterator of iterators into a single iterator. | | inspect | Calls a callback function on each item of an iterator, without modifying the returned items. | | map | Maps each item of an iterator using a callback function. | +| once | Iterator which returns a given item once. Equivalent to `citer_take(citer_repeat(item), 1)`. | | over_array | Iterates over the items in an array. Returns a pointer to each item in the array as the item. | | repeat | Iterator which repeatedly returns the same item. | | skip | Skips the first N items of another iterator. | diff --git a/src/repeat.h b/src/repeat.h index accd594..3d6981a 100644 --- a/src/repeat.h +++ b/src/repeat.h @@ -23,4 +23,14 @@ iterator_t *citer_repeat(void *); +/* + * Create an iterator that yields a single item. + * + * Parameters: + * item - The item to yield. + * + * The returned iterator must be freed after use with citer_free(). + */ +#define citer_once(item) citer_take(citer_repeat(item), 1) + #endif /* _CITER_REPEAT_H_ */