The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Mark Elston (133) [Avatar] Offline
#1
In section 3.7 you present case classes extending QueryOption for Sort, Skip, and Limit (as well as NoOption) (page 79). Then you have the Query case class which provides sort, skip and limit methods (page 80). Then you provide the following example code:

var rangeQuery = ...
var richQuery = Query(rangeQuery).skip(20).limit(10)

When you show the 'find' function taking a Query object, (page 82) I wound up confused over the order of the application of the Query operations. From the example code on page 80 the resulting 'richQuery' var would result in a 'Limit' query with a 'Skip' query as its 'next' value. The code on page 82 calls applyOptions recurively with a cursor modification appropriate to the type of QueryOption object, followed by the 'next' value.

However, since the arguments to functions are evaluated before calling the function this means that the cursor operations are performed prior to the recursive call. This would imply that, instead of skipping the first 20 records and then limiting to 10 records, the returned set is first limited to 10 records and *then* the first 20 records are skipped, resulting in no records being returned.

Have I missed something here?

Mark