use

fun <R> use(consumer: (Sequence<T>) -> R): R

Creates a new cursor and treats it as a Sequence, invokes the given consumer function and closes the cursor down correctly whether an exception is thrown or not.

This allows the MongoIterable to be safely treated as a lazily evaluated sequence.

Note: Sequence filters and aggregations have a performance cost, it is best to use server side filters and aggregations where available.

Return

the result of the consumer

Parameters

R

the result type

consumer

the sequence consumer