Initiators are factory functions for creating Queryables.
Initiators are so-called because they are used to initiate a query expression using the fluent interface of asq which uses method-chaining to compose complex queries from the query operators provided by queryables.
query | Make an iterable queryable. |
empty | An empty Queryable. |
integers | Generates in sequence the integral numbers within a range. |
repeat | Generate a sequence with one repeated value. |
Make an iterable queryable.
Use this function as an entry-point to the asq system of chainable query methods.
Note
Currently this factory only provides support for objects supporting the iterator protocol. Future implementations may support other providers.
Parameters: | iterable – Any object supporting the iterator protocol. |
---|---|
Returns: | An instance of Queryable. |
Raises : | TypeError - If iterable is not actually iterable |
Examples
Create a queryable from a list:
>>> from asq.initiators import query
>>> a = [1, 7, 9, 4, 3, 2]
>>> q = query(a)
>>> q
Queryable([1, 7, 9, 4, 3, 2])
>>> q.to_list()
[1, 7, 9, 4, 3, 2]
An empty Queryable.
Note
The same empty instance will be returned each time.
Returns: | A Queryable over an empty sequence. |
---|
Examples
Create a queryable from a list:
>>> from asq.initiators import empty
>>> q = empty()
>>> q
Queryable(())
>>> q.to_list()
[]
See that empty() always returns the same instance:
>>> a = empty()
>>> b = empty()
>>> a is b
True
Generates in sequence the integral numbers within a range.
Note
This method uses deferred execution.
Parameters: |
|
---|---|
Returns: | A Queryable over the specified range of integers. |
Raises : | ValueError - If count is negative. |
Examples
Create the first five integers:
>>> from asq.initiators import integers
>>> numbers = integers(0, 5)
>>> numbers
Queryable(range(0, 5))
>>> numbers.to_list()
[0, 1, 2, 3, 4]
Generate a sequence with one repeated value.
Note
This method uses deferred execution.
Parameters: |
|
---|---|
Raises : | ValueError - If the count is negative. |
Examples
Repeat the letter x five times:
>>> from asq.initiators import repeat
>>> q = repeat('x', 5)
>>> q
Queryable(repeat('x', 5))
>>> q.to_list()
['x', 'x', 'x', 'x', 'x']