Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.29 KB | None | 0 0
  1. package game.utils
  2.  
  3. import io.vavr.collection.Stream
  4.  
  5.  
  6. class TestStreamSpec {
  7.  
  8.     ArrayList<String> data
  9.  
  10. //    TestStreamSpec() {}
  11.  
  12. //    TestStreamSpec(List<String> data) {
  13. //        this.data = data
  14. //    }
  15.  
  16.     List<String> getData(Integer lastId, Integer max) {
  17.         List<String> series = []
  18.         data.eachWithIndex { String entry, int i ->
  19.             if (i >= lastId && i < lastId + max) {
  20.                 series.add(entry)
  21.             }
  22.         }
  23.         series
  24.     }
  25.  
  26.     Stream<List<String>> testPaging(Integer max) {
  27.         int lastId = 0
  28.         def r = Stream.continually { ->
  29.             if (lastId) {
  30.                 lt 'id', lastId
  31.             }
  32.             def result = getData(lastId, max)
  33.             lastId += result.size()
  34.             result
  35.         }.takeUntil { List<String> it ->
  36.             println it.empty
  37.             it.empty
  38.         }.map { List<String> aData ->
  39.             println "map ${aData}"
  40.             aData
  41.         }
  42.         r
  43.     }
  44.  
  45.     public static void main(String[] args) {
  46. //        new TestStreamSpec(Range['a'..'b']).testPaging(10)
  47.         def t = new TestStreamSpec()
  48.         t.data = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p']
  49. //        println t.getData(0, 5)
  50.         println t.testPaging(5)
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement