Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game.utils
- import io.vavr.collection.Stream
- class TestStreamSpec {
- ArrayList<String> data
- // TestStreamSpec() {}
- // TestStreamSpec(List<String> data) {
- // this.data = data
- // }
- List<String> getData(Integer lastId, Integer max) {
- List<String> series = []
- data.eachWithIndex { String entry, int i ->
- if (i >= lastId && i < lastId + max) {
- series.add(entry)
- }
- }
- series
- }
- Stream<List<String>> testPaging(Integer max) {
- int lastId = 0
- def r = Stream.continually { ->
- if (lastId) {
- lt 'id', lastId
- }
- def result = getData(lastId, max)
- lastId += result.size()
- result
- }.takeUntil { List<String> it ->
- println it.empty
- it.empty
- }.map { List<String> aData ->
- println "map ${aData}"
- aData
- }
- r
- }
- public static void main(String[] args) {
- // new TestStreamSpec(Range['a'..'b']).testPaging(10)
- def t = new TestStreamSpec()
- t.data = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p']
- // println t.getData(0, 5)
- println t.testPaging(5)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement