blade documentation

blade.xcmp

«  blade Documentation   ::   Contents   ::   blade.xfilter  »

blade.xcmp

blade comparison operations

blade.xcmp.xall(iterable, test)

Discover if test is True for all items in iterable.

Parameters:
Returns:

bool

>>> from blade.xcmp import xall
>>> xall([2, 4, 6, 8], lambda x: x % 2 == 0)
True
blade.xcmp.xany(iterable, test)

Discover if test is True for any items in iterable.

Parameters:
Returns:

bool

>>> from blade.xcmp import xany
>>> xany([1, 4, 5, 9], lambda x: x % 2 == 0)
True
blade.xcmp.xdiff(iterable, symmetric=False)

Discover difference within a series of iterable items in iterable.

Parameters:
  • iterableiterable
  • symmetric (bool) – return symmetric difference
Returns:

iterator of items

>>> from blade.xcmp import xdiff
>>> # default behavior
>>> list(xdiff([[1, 2, 3, 4, 5], [5, 2, 10], [10, 11, 2]]))
[1, 3, 4]
>>> # symmetric difference
>>> list(xdiff([[1, 2, 3, 4, 5], [5, 2, 10], [10, 11, 2]], True))
[1, 2, 3, 4, 11]
blade.xcmp.xintersect(iterable)

Discover intersection within a series of iterable items in iterable.

Parameters:iterableiterable
Returns:iterator of items
>>> from blade.xcmp import xintersect
>>> list(xintersect([[1, 2, 3], [101, 2, 1, 10], [2, 1]]))
[1, 2]
blade.xcmp.xunion(iterable)

Discover union within a series of iterable items in iterable.

Parameters:iterableiterable
Returns:iterator of items
>>> from blade.xcmp import xunion
>>> list(xunion([[1, 2, 3], [101, 2, 1, 10], [2, 1]]))
[1, 10, 3, 2, 101]
blade.xcmp.xunique(iterable, test=None)

Discover unique items in iterable that pass test.

Parameters:
Returns:

iterator of items

>>> from blade.xcmp import xunique
>>> # no key function
>>> list(xunique([1, 2, 1, 3, 1, 4]))
[1, 2, 3, 4]
>>> # with key function
>>> list(xunique([1, 2, 1, 3, 1, 4], round))
[1.0, 2.0, 3.0, 4.0]

«  blade Documentation   ::   Contents   ::   blade.xfilter  »