Skip to main content

An easy way to make lambdas by partial application of python operators.

Inspired by Perl 6 one, see http://perlcabal.org/syn/S02.html#The_Whatever_Object

Usage

from whatever import _, that

# get a list of guys names
names = map(_.name, guys)
names = map(that.name, guys)

odd = map(_ * 2 + 1, range(10))

squares = map(_ ** 2, range(100))
small_squares = filter(_ < 100, squares)

best = max(tries, key=_.score)
sort(guys, key=-that.height)

factorial = lambda n: reduce(_ * _, range(2, n+1))

NOTE: chained comparisons cannot be implemented since there is no boolean overloading in python.

CAVEATS

In some special cases whatever can cause confusion:

_.attr # this makes callable
obj._  # this fetches '_' attribute of obj

_[key] # this works too
d[_]   # KeyError, most probably

_._    # short for attrgetter('_')
_[_]   # short for lambda d, k: d[k]

if _ == 'Any value':
    # You will get here, definitely
    # `_ == something` produces callable, which is true

[1, 2, _ * 2, None].index('hi') # => 2, since bool(_ * 2 == 'hi') is True

Also, whatever sometimes fails on late binding:

(_ * 2)('2') # -> NotImplemented

Release files for whatever 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whatever 0.7
File Size Uploaded
whatever-0.7.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for whatever 0.7
File Interpreter ABI Platform
whatever-0.7-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / whatever-0.7.tar.gz

Download URL whatever-0.7.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
82d9ab46297c41e2fd4947684f666d4f06c632edd458caf4468417da51c84581
BLAKE2b-256 checksum
How to use checksums
13d8e640240bc42f78846b691b16d66591e4fde0c3db7a3dd1085cd82b3130a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / whatever-0.7-py3-none-any.whl

Download URL whatever-0.7-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a862efbb11a88e9b162e88a59a5eb8b1e656df6c39c6e818f7902bf1d27d728
BLAKE2b-256 checksum
How to use checksums
752b3ae9940b7e3a368160ba183aa97d0493b803da3f73dd46bb9808be0314eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.7 This release

2 release files

0.6

1 release file

0.5

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page