From e7471d1a36ab71abdab4d1f3cd8f246108b42eb6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 2 May 2020 11:12:18 +0100 Subject: Add convenience functions --- jq.pyx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'jq.pyx') 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) -- cgit v1.2.3