Skip to content

Commit

Permalink
readme: added pluck2 ref
Browse files Browse the repository at this point in the history
  • Loading branch information
randomir committed May 2, 2017
1 parent f45141e commit 35efdd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ indices. Slices over list items are also supported.
``plucky.pluckable`` will happily wrap dictionary- or list-like objects and allow
for chained soft plucking with attribute and item getters (e.g. ``.attr``,
``["key"]``, ``[idx]``, ``[a:b]``, or a combination: ``["key1", "key2"]``,
and ``[0, 3:7, ::-1]``)
and ``[0, 3:7, ::-1]``; even: ``["length", 0:5]``).

``plucky.pluck2`` is a next generation of ``pluck``: it unwraps ``pluckable``
(Python) syntax from a supplied string selector.

``plucky.merge`` facilitates recursive merging of two data structures, reducing
leaf values with the provided binary operator.
Expand All @@ -45,11 +48,13 @@ Usage
from plucky import pluck, merge, pluckable
pluck(obj, 'selector.*.path.2')
pluck(obj, 'selector.path.2')
merge({"x": 1, "y": 0}, {"x": 2})
pluckable(obj).users[2:5, 10:15].name["first", "middle"]
pluckable(obj).users[2:5, 10:15].name["first", "middle"].value
pluck2(obj, 'users[2:5, 10:15].name["first", "middle"]')
Examples
Expand Down Expand Up @@ -77,7 +82,7 @@ Examples
pluck(obj, 'users.1.name')
# -> {'last': 'Bono'}
pluck(obj, 'users.*.name.last')
pluck(obj, 'users.name.last')
# -> ['Smith', 'Bono']
pluck(obj, 'users.*.name.first')
Expand Down Expand Up @@ -113,7 +118,7 @@ More Examples! :)
pluck([1,2,3], '::-1')
# -> [3,2,1]
pluck([1, {'val': 2}, 3], '*.val')
pluck([1, {'val': 2}, 3], 'val')
# -> [2]
pluck([1, {'val': [1,2,3]}, 3], '1.val.-1')
Expand All @@ -133,3 +138,6 @@ More Examples! :)
pluckable(obj).users[:, ::-1].name.last[0, -1].value
# -> ['Smith', 'Smith']
pluck2(obj, 'users[:, ::-1].name.last[0, -1]')
# -> ['Smith', 'Smith']
2 changes: 1 addition & 1 deletion plucky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .compat import basestring
from .structural import pluckable

__all__ = ["pluck", "merge", "pluckable"]
__all__ = ["pluck", "merge", "pluckable", "pluck2"]


def pluck(obj, selector, default=None):
Expand Down

0 comments on commit 35efdd6

Please sign in to comment.