Skip to content

Commit

Permalink
Merge pull request #100 from mahmoud/streaming
Browse files Browse the repository at this point in the history
Streaming
  • Loading branch information
mahmoud committed Oct 20, 2019
2 parents 22d6c50 + c934360 commit 41c9752
Show file tree
Hide file tree
Showing 7 changed files with 648 additions and 29 deletions.
68 changes: 45 additions & 23 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,26 @@ specifiers to declare away overly branchy procedural code.
.. autodata:: glom.SKIP
.. autodata:: glom.STOP

Target mutation with Assign
^^^^^^^^^^^^^^^^^^^^^^^^^^^

*New in glom 18.3.0*

Most of glom's API design defaults to safely copying your data. But
such caution isn't always justified.

When you already have a large or complex bit of nested data that you
are sure you want to modify in-place, glom has you covered, with the
:func:`~glom.assign` function, and the :func:`~glom.Assign` specifier
type.

.. autofunction:: glom.assign
Stream processing iterables with Iter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: glom.Assign
*New in glom 19.2.0*

.. autoclass:: glom.Iter

Reducing lambda usage with Call
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: map
.. automethod:: filter
.. automethod:: chunked
.. automethod:: split
.. automethod:: flatten
.. automethod:: unique
.. automethod:: limit
.. automethod:: slice
.. automethod:: takewhile
.. automethod:: dropwhile
.. automethod:: all
.. automethod:: first

There's nothing quite like inserting a quick lambda into a glom spec
to get the job done. But once a spec works, how can it be cleaned up?

.. autofunction:: glom.Call

Combining iterables with Flatten and friends
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -99,15 +94,40 @@ specifier types and two convenience functions:
.. autoclass:: glom.Fold


Target mutation with Assign
^^^^^^^^^^^^^^^^^^^^^^^^^^^

*New in glom 18.3.0*

Most of glom's API design defaults to safely copying your data. But
such caution isn't always justified.

When you already have a large or complex bit of nested data that you
are sure you want to modify in-place, glom has you covered, with the
:func:`~glom.assign` function, and the :func:`~glom.Assign` specifier
type.

.. autofunction:: glom.assign

.. autoclass:: glom.Assign


Reducing lambda usage with Call
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There's nothing quite like inserting a quick lambda into a glom spec
to get the job done. But once a spec works, how can it be cleaned up?

.. autofunction:: glom.Call


Object-oriented access and method calls with ``T``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

glom's shortest-named feature may be its most powerful.

.. autodata:: glom.T

.. _exceptions:

.. _check-specifier:

Validation with Check
Expand All @@ -120,6 +140,8 @@ step, you can do these checks inline with your glom spec, using

.. autoclass:: glom.Check

.. _exceptions:

Exceptions
----------

Expand Down
5 changes: 5 additions & 0 deletions glom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@

from glom.reduction import Sum, Fold, Flatten, flatten, FoldError, Merge, merge
from glom.mutation import Assign, assign, PathAssignError

# there's no -ion word that really fits what "streaming" means.
# generation, production, iteration, all have more relevant meanings
# elsewhere. (maybe procrastination :P)
from glom.streaming import Iter
5 changes: 3 additions & 2 deletions glom/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ def __init__(self, spec, scope=None):
def glom(self, target, **kw):
scope = dict(self.scope)
scope.update(kw.get('scope', {}))
kw['scope'] = scope
return glom(target, self.spec, **kw)
kw['scope'] = ChainMap(scope)
glom_ = scope.get(glom, glom)
return glom_(target, self.spec, **kw)

def glomit(self, target, scope):
scope.update(self.scope)
Expand Down

0 comments on commit 41c9752

Please sign in to comment.