Struct Leap::Unity::Query::Query

struct Leap.Unity.Query.Query<T>

A Query object is a type of immutable ordered collection of elements that can be used to perform useful queries. These queries are very similar to LINQ style queries, providing useful methods such as Where, Select, Concat, etc….

The Query struct and its interfaces use a pooling strategy backed by ArrayPool to incur an amortized cost of zero GC allocations.

A Query struct is immutable, and so cannot be modified once it has been created. You can use a query in few ways:

  • The simplest way is to call an operator method such as Where or Select. These methods CONSUME the query to produce a new query. Trying to use the original query after it has been consumed will cause a runtime error.

  • The next way is to call a collapsing operator, which will consume the query and produce a non-query value or other side-effect. Examples of collapsing operators are First, Last, or ElementAt.

  • The last way to use a query is to Deconstruct it, by calling a Deconstruct method to destroy the query and get access to its underlying data. You will be responsible for cleaning up or disposing the data you get.

Public Functions

Query (T[] array, int count)

Constructs a new query given a source array and a count. The query assumes ownership of the array, so you should not use it or store it after the query is constructed.

Query (ICollection<T> collection)

Constructs a new query of the given collection.

Query (Query<T> other)

Constructs a query that is an exact copy of another query.

Query<K> OfType<K> ()

Returns a new Query representing only the items of the current Query that are of a specific type.

For example (“A”, 1, null, 5.0f, 900, “hello”).Query().OfType<string>() would result in (“A”, “hello”)

Query<K> Cast<K> ()

Returns a new Query representing the current query sequence where each element is cast to a new type.

void Dispose ()

Disposes of the resources that this query holds. The Query cannot be used after this method is called.

void Deconstruct (out T[] array, out int count)

Deconstructs this Query into its base elements, the array and the count. The caller assumes ownership of the array and is responsible for managing its lifecycle. The Query cannot be used after this method is called.

QuerySlice Deconstruct ()

Deconstructs this Query into a simple QuerySlice construct. This is simply a utility overload of the regular Deconstruct method. The user is still responsible for managing the memory lifecycle of the returned slice. The Query cannot be used after this method is called.

struct Enumerator : public IEnumerator<T>
struct QuerySlice : public IDisposable