Skip to main content

python-rm

Provides the Result and Maybe monads for effective functional programming.

Installation

With uv (recommended):

uv add python-rm

With pip:

pip install python-rm

Examples

Result

import rm

def divide(a: float, b: float) -> rm.Result[float, str]:
    if b == 0:
        return rm.Err("cannot divide by zero")
    return rm.Ok(a / b)


ok_value = (
    divide(8, 2)
    .map(lambda v: v**2)
    .unwrap_or(5)
)
print(value) #> 16

err_value = divide(10, 0).unwrap_or(5)
print(value) #> 5

Maybe

import rm

users: dict[int, str] = {
    0: "Luke",
    1: "Leia",
    2: "Han"
}

def get_user(id: int) -> rm.Maybe[str]:
    user = users.get(id)
    if user is None:
        return rm.Nothing
    return rm.Some(user)


some_value = (
    get_user(0)
    .map(lambda v: v.upper())
    .unwrap_or("VADER")
)
print(some_value) #> LUKE

nothing_value = (
    get_user(10)
    .map(lambda v: v.lower())
    .unwrap_or("vader")
)
print(nothing_value) #> vader

Download files

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

Source Distribution

python_rm-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

python_rm-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file python_rm-0.1.0.tar.gz.

File metadata

  • Download URL: python_rm-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python_rm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50ea81176f4819aa053cedbb59d795cb3be80da04afed8be61e57a297e1d8e3e
MD5 0cb7477c21541fcf79d3cc3a2e8cf4c5
BLAKE2b-256 858fc6c16baf63859db3bdc6b3a36e0a08c6a6300e2b2dbb18fe184ba1dd853e

See more details on using hashes here.

File details

Details for the file python_rm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_rm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python_rm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ef4deaed90ebc7591d26b950cce13c04c31c61e23c888a85ab322d9a1b685e2
MD5 bb107672bd7c1a1d229ffc999fef4331
BLAKE2b-256 f1787467506ab78e4b7d9e37562a63180ca59717427d6f8df6dcee5690a281c6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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