-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transducers): add page() xform, update readme
- Loading branch information
1 parent
596ed7a
commit 855d803
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Transducer } from "../api"; | ||
import { comp } from "../func/comp"; | ||
import { drop } from "./drop"; | ||
import { take } from "./take"; | ||
|
||
/** | ||
* Pagination helper. Returns transducer which extracts | ||
* only items for given page number (and page length, | ||
* default 10). When composing with other transducers, | ||
* it's most efficient if `page()` is used prior to | ||
* any heavy processing steps. | ||
* | ||
* ``` | ||
* [...iterator(page(0, 5), range(12))] | ||
* // [ 0, 1, 2, 3, 4 ] | ||
* | ||
* [...iterator(page(1, 5), range(12))] | ||
* // [ 5, 6, 7, 8, 9 ] | ||
* | ||
* [...iterator(page(2, 5), range(12))] | ||
* // [ 10, 11 ] | ||
* | ||
* [...iterator(page(3, 5), range(12))] | ||
* // [] | ||
* ``` | ||
* | ||
* @param page | ||
* @param pageLen | ||
*/ | ||
export function page<T>(page: number, pageLen = 10): Transducer<T, T> { | ||
return comp(drop(page * pageLen), take(pageLen)); | ||
} |