Skip to main content

Syntactic Sugar for Lambda Expressions

Project description

Highlambder - there can be only one... lambda to rule them all

Syntactic sugar for Python lambda expressions. Make your anonymous functions shorter, more expressive, and (let's be honest) just more fun.

there can be only one

Image used under fair use, for illustrative and non-commercial purposes. All rights to the character and image belong to their respective owners.

What is Highlambder?

Highlambder lets you write more elegant and compact code by replacing Python’s lambda keyword with something cleaner and more intuitive: a symbolic placeholder that behaves like a function.

You get concise, readable lambdas with operator overloading — no more lambda x: boilerplate.

Installation

pip install highlambder

Quick Examples

from highlambder import L as λ

λ (10)  # -> 10

(λ + 5) (10)  # -> 15

(λ * 5) (10)  # -> 50

(3 + λ * 2) (10)  # -> 23

(40 / λ / 5) (2)  # -> 4

(10 * λ[1]) ([1, 2, 3])  # -> 20

(-1 + λ * 5 / λ + 1) (13)  # -> 5

(λ * 2 + λ * 4 + λ) (10)  # -> 70

(λ['A'] + λ['B']) ({'A': 3, 'B': 4})  # -> 7

(λ + λ) (2)  # -> 4

map(λ * 2, range(5)) # -> [0, 2, 4, 6, 8]

("It's a Me, " + λ) ('Mario!') # ->  'It's a Me, Mario!'

pandas and NumPy support (partially supported, work-in-progress)

import pandas as pd
import numpy as np
from highlambder import L as λ

# pandas:
s = pd.Series([1, 2, 3, 4])
assert pd.Series.equals(
    2 * s,
    s.map(2 * λ),
)

df = pd.DataFrame({
    'A': [1, 1, 2, 2],
    'B': [5, 6, 7, 8],
    'C': ['banana', 'apple', 'kiwi', 'orange'],
})

assert pd.DataFrame.equals(
    df.assign(D=lambda d: d.A + 20),
    df.assign(D=λ.A + 20),
)

# String operations
assert pd.DataFrame.equals(
    df.assign(D=lambda d: d['C'].str.len() * 2),
    df.assign(D=λ['C'].str.len * 2),
)

# NumPy:
assert (λ + 2)(np.int64(2)) == 4

assert (λ.max)(np.array([3, 4, 5, 6, 7, 8])) == 8

Limitations (for now)

  • Only single-argument functions are supported.
  • Calling a function passing λ as an arument usually doesn't work. For example: len(λ).

These limitations may be lifted in future versions.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

highlambder-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

highlambder-0.1.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file highlambder-0.1.1.tar.gz.

File metadata

  • Download URL: highlambder-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for highlambder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fdf99a9fb45ff1d1012af2d530191a9004adff99e9c4c40c8655d6d4cf131c98
MD5 2a527bef1e21eb1d146171b7855bcee7
BLAKE2b-256 d5a8ba8075905a0925f2b348e470d2f571f95d0f7af80c637aeb8b0cf41b2e18

See more details on using hashes here.

File details

Details for the file highlambder-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: highlambder-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for highlambder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab3fa603e164572b9af81d55f7cf69eb9667437304d0a6bfdfaeb4f513f1b041
MD5 6672e25fcfbe72c6c63e3a387b91ffd7
BLAKE2b-256 bac27826f4d7a4bdd6f6474f68aecf83a49e41719301c4afabbb94081a7cc041

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page