diff options
| author | Michael Williamson <mike@zwobble.org> | 2020-05-02 11:12:18 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2020-05-02 11:12:18 +0100 |
| commit | e7471d1a36ab71abdab4d1f3cd8f246108b42eb6 (patch) | |
| tree | 65f1d59bb8a3761c0c4fd3eec75ee4980e1eb60c /jq.pyx | |
| parent | fa7399eb01fce0a81e617af03d752527093e7d72 (diff) | |
Add convenience functions
Diffstat (limited to 'jq.pyx')
| -rw-r--r-- | jq.pyx | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -174,7 +174,7 @@ cdef class _ProgramWithInput(object): return list(self) def first(self): - return next(iter(self)) + return next(_iter(self)) cdef class _ResultIterator(object): @@ -238,6 +238,25 @@ cdef class _ResultIterator(object): raise StopIteration() +def all(program, value=_NO_VALUE, text=_NO_VALUE): + return compile(program).input(value, text=text).all() + + +def first(program, value=_NO_VALUE, text=_NO_VALUE): + return compile(program).input(value, text=text).first() + + +_iter = iter + + +def iter(program, value=_NO_VALUE, text=_NO_VALUE): + return _iter(compile(program).input(value, text=text)) + + +def text(program, value=_NO_VALUE, text=_NO_VALUE): + return compile(program).input(value, text=text).text() + + # Support the 0.1.x API for backwards compatibility def jq(object program): return compile(program) |
