Skip to content

Commit 66921e1

Browse files
committed
Add sequence operator
1 parent fc2c326 commit 66921e1

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

terminusdb_client/woqlquery/woql_query.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,42 @@ def in_range(self, value, start, end):
22602260
self._cursor["end"] = self._clean_object(end)
22612261
return self
22622262

2263+
def sequence(self, value, start, end, step=None, count=None):
2264+
"""Generates a sequence of values in the half-open range [start, end).
2265+
When value is unbound, produces each value via backtracking.
2266+
2267+
Parameters
2268+
----------
2269+
value : str or number
2270+
the generated sequence value (or variable)
2271+
start : str or number
2272+
the inclusive start of the sequence
2273+
end : str or number
2274+
the exclusive end of the sequence
2275+
step : str or number, optional
2276+
increment per step
2277+
count : str or number, optional
2278+
total count (validates if bound, unifies if unbound)
2279+
2280+
Returns
2281+
-------
2282+
WOQLQuery object
2283+
query object that can be chained and/or execute
2284+
"""
2285+
if value is None or start is None or end is None:
2286+
raise ValueError("Sequence takes at least three parameters")
2287+
if self._cursor.get("@type"):
2288+
self._wrap_cursor_with_and()
2289+
self._cursor["@type"] = "Sequence"
2290+
self._cursor["value"] = self._clean_object(value)
2291+
self._cursor["start"] = self._clean_object(start)
2292+
self._cursor["end"] = self._clean_object(end)
2293+
if step is not None:
2294+
self._cursor["step"] = self._clean_object(step)
2295+
if count is not None:
2296+
self._cursor["count"] = self._clean_object(count)
2297+
return self
2298+
22632299
def opt(self, query=None):
22642300
"""The Query in the Optional argument is specified as optional
22652301

0 commit comments

Comments
 (0)