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 --- README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'README.rst') diff --git a/README.rst b/README.rst index 1217c3c..a3af21d 100644 --- a/README.rst +++ b/README.rst @@ -110,6 +110,16 @@ Call ``iter()`` to get all of the output elements as an iterator: assert next(iterator, None) == 4 assert next(iterator, None) == None +Convenience functions are available to get the output for a program and input in one call: + +.. code-block:: python + + assert jq.first(".[] + 1", [1, 2, 3]) == 2 + assert jq.first(".[] + 1", text="[1, 2, 3]") == 2 + assert jq.text(".[] + 1", [1, 2, 3]) == "2\n3\n4" + assert jq.all(".[] + 1", [1, 2, 3]) == [2, 3, 4] + assert list(jq.iter(".[] + 1", [1, 2, 3])) == [2, 3, 4] + The original program string is available on a compiled program as the ``program_string`` attribute: .. code-block:: python -- cgit v1.2.3