Skip to main content

Functor for Python, with a Pythonic UX

Project description

fmappy

Python Workflow codecov CodeFactor License: MIT

Brings the Functionality of the Functor to Python.

>>> fmap(square, dict(one=1, two=2, three=3))
{'one': 1, 'two': 4, 'three': 9}

I miss this. The implementation of map always returns a generator; but sometimes I want to keep the container type, just map the contained values. This is what the functiona-programming world knows as a Functor.

Why this Library?

>>> numbers = {'one': 1, 'two': 2, 'three': 3}
>>> squared = {k: v*v for k, v in numbers.items()}
>>> names = numbers.keys()
>>> NAMES = tuple(n.upper() for n in names)
>>> NAMES_TOO = tuple(map(str.upper, names))

We have got used to these patterns: dict-comprehensions, using map and storing it into a tuple for later use. So used that we don't realize it is chipping away some of our mental capacity while reading and writing code. I want this to stop: a use case that occurs so often has the right to be streamlined into something simpler, and we can borrow gratefully from the functional programming world here.

A number of libraries exist for full fledged functional programming in Python. These libraries assume an FP background. I want a library that starts from the Python syntax, and adds as little clutter as possible - as many batteries included.

As Alan Kaye said: make Simple things Simple, and Hard things Possible.

I bumped onto this gist and realized this was something: We Already Needed It For A Long Time (WANIFALT). This is simple enough to use for even starting Pythonistas. And it allows enough extensions for the professional to integrate it in their code base.

Goals

  • import this
  • cover 95% of the day to day use cases (to my knowledge)
  • wrist-friendly: use fmap instead of map and you're there
  • Closed for Change, Open for Extension

Other Libraries

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fmappy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.10

File hashes

Hashes for fmappy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee7252d8d1e9334ea8e60d7c2498ef0e55e167234a9030b8b8e345fd4dd40c20
MD5 b3e28b9c5efa497d22d9d4f9488a7804
BLAKE2b-256 ecc9290735359cb85aa6b67543375cadbd9aa8457cfd90165d6020b1f28f47a0

See more details on using hashes here.

Supported by

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