summaryrefslogtreecommitdiff
path: root/jq.pyx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2020-05-02 11:12:18 +0100
committerMichael Williamson <mike@zwobble.org>2020-05-02 11:12:18 +0100
commite7471d1a36ab71abdab4d1f3cd8f246108b42eb6 (patch)
tree65f1d59bb8a3761c0c4fd3eec75ee4980e1eb60c /jq.pyx
parentfa7399eb01fce0a81e617af03d752527093e7d72 (diff)
Add convenience functions
Diffstat (limited to 'jq.pyx')
-rw-r--r--jq.pyx21
1 files changed, 20 insertions, 1 deletions
diff --git a/jq.pyx b/jq.pyx
index 229faa4..f1c6a48 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -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)