sidekick.op

This module exposes functionality analogous to the operator module in the standard lib. The main difference is that binary operators are curried and all functions are fn-functions. So we can use it as a drop-in replacement to the operator module:

>>> from sidekick import op
>>> op.add(1, 2)
3

But one that accepts additional idioms

>>> succ = op.add(1)
>>> succ(41)
42

API reference

fn-aware functions from the builtin operator module.

sidekick.op.setitem

Same as a[b] = c.

sidekick.op.add

Same as a + b.

sidekick.op.and_

Same as a & b.

sidekick.op.concat

Same as a + b, for a and b sequences.

sidekick.op.contains

Same as b in a (note reversed operands).

sidekick.op.count_of

Return the number of times b occurs in a.

sidekick.op.delitem

Same as del a[b].

sidekick.op.eq

Same as a == b.

sidekick.op.floordiv

Same as a // b.

sidekick.op.ge

Same as a >= b.

sidekick.op.getitem

Same as a[b].

sidekick.op.gt

Same as a > b.

sidekick.op.iadd

Same as a += b.

sidekick.op.iand

Same as a &= b.

sidekick.op.iconcat

Same as a += b, for a and b sequences.

sidekick.op.ifloordiv

Same as a //= b.

sidekick.op.ilshift

Same as a <<= b.

sidekick.op.imod

Same as a %= b.

sidekick.op.imul

Same as a *= b.

sidekick.op.index_of

Return the first index of b in a.

sidekick.op.ior

Same as a |= b.

sidekick.op.ipow

Same as a **= b.

sidekick.op.irshift

Same as a >>= b.

sidekick.op.is_

Same as a is b.

sidekick.op.is_not

Same as a is not b.

sidekick.op.isub

Same as a -= b.

sidekick.op.itruediv

Same as a /= b.

sidekick.op.ixor

Same as a ^= b.

sidekick.op.le

Same as a <= b.

sidekick.op.lshift

Same as a << b.

sidekick.op.lt

Same as a < b.

sidekick.op.mod

Same as a % b.

sidekick.op.mul

Same as a * b.

sidekick.op.ne

Same as a != b.

sidekick.op.or_

Same as a | b.

sidekick.op.pow

Same as a ** b.

sidekick.op.rshift

Same as a >> b.

sidekick.op.sub

Same as a - b.

sidekick.op.div

Same as a / b.

sidekick.op.truediv

Same as a / b.

sidekick.op.xor

Same as a ^ b.

sidekick.op.abs

Same as abs(a).

sidekick.op.index

Same as a.__index__().

sidekick.op.inv

Same as ~a.

sidekick.op.invert

Same as ~a.

sidekick.op.neg

Same as -a.

sidekick.op.not_

Same as not a.

sidekick.op.pos

Same as +a.

sidekick.op.truth

Return True if a is true, False otherwise.

sidekick.op.matmul

Same as a @ b.

sidekick.op.imatmul

Same as a @= b.

sidekick.op.length_hint

Return an estimate of the number of items in obj.

This is useful for presizing containers when building from an iterable.

If the object supports len(), the result will be exact. Otherwise, it may over- or under-estimate by an arbitrary amount. The result will be an integer >= 0.

sidekick.op.attrgetter[source]

attrgetter(attr, …) –> attrgetter object

Return a callable object that fetches the given attribute(s) from its operand. After f = attrgetter(‘name’), the call f(r) returns r.name. After g = attrgetter(‘name’, ‘date’), the call g(r) returns (r.name, r.date). After h = attrgetter(‘name.first’, ‘name.last’), the call h(r) returns (r.name.first, r.name.last).

sidekick.op.itemgetter[source]

itemgetter(item, …) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

sidekick.op.methodcaller[source]

methodcaller(name, …) –> methodcaller object

Return a callable object that calls the given method on its operand. After f = methodcaller(‘name’), the call f(r) returns r.name(). After g = methodcaller(‘name’, ‘date’, foo=1), the call g(r) returns r.name(‘date’, foo=1).