Skip to content

Commit

Permalink
Add once iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkasad committed May 13, 2024
1 parent 12874fb commit 985bda1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
10 changes: 10 additions & 0 deletions src/repeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit 985bda1

Please sign in to comment.