Scala, paging without max -


i have query api pagination. because api weird have query until response empty (contains no items).

actually done in java do-while :

do {    objects = doquery(from);   += 200 } while ( !objects.isempty() ) 

but convert in scala. first idea use stream step , takewhile :

stream.iterate(0)(_+200)   .map( => doquery(from) )   .takewhile( objects -> !objects.isempty ) 

but changes make doquery returns future. cannot test in takewhile , have no best idea on how (maybe recursive call). new code akka actor tell each object (no need return anything)

this gives stream[future[(boolean, t)]], first time false rest empty. not sure how takewhile without blocking.

stream.iterate(0)(_+200)   .scanleft(future((true, list[int]())))({case (prev, from) =>       prev.flatmap({case (cont, _) =>         if(cont) {           doquery(from).map(res => (res.isempty, res.tolist))         } else {           future((false, list()))         }       })     }) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -