Skip to main content

scala-option

python PyPI - Implementation PyPI - Wheel Test Coverage License

Scala like Option type in Python.

Implements the child classes None and Some, but renamed to none and some, since None is a built-in type in Python.

Table of Contents

Installation

Requirements

This library requires Python 3.12 or newer, because it uses the latest syntax for generics, introduced in Python 3.12.

Download Python

You can check your python version by running the command:

Windows:

py --version

Linux and macOS:

python3 --version

You can download Python from: Download Python

Installing Using PIP

You can install the package by running the command:

pip install scala-option

Building from Source

First, clone the repository or download source code from the latest release.

Next, install the build package:

pip install build

Then, build the project by running:

Windows:

py -m build

Linux and macOS:

python -m build

To install the package locally, run:

pip install -e .

Usage

Quick Start

Once you have installed the package (see Installation), you just need to add the import statement:

Attention: the package name contains an underscore instead of a dash

from scala_option import Option, none, some

Then you can begin using the Option type. Here's a little example:

import random
from scala_option import Option, none, some

def fivety_fivety() -> Option[int]:
  if random.random() <= 0.5:
    return some(1)
  else:
    return none

def print_option(option: Option) -> None:
  if option.is_empty():
    print("You got nothing!")
  else:
    print(f"You got something: {option.get()}")

Implemented Methods

The Option type implements many of the most important methods of the Scala Option (Scala Option documentation).

The methods are documented using Docstrings.

List of methods:

  • get()
  • is_empty()
  • non_empty()
  • get_or_else(default)
  • or_else(alternative)
  • map(f)
  • flat_map(f)
  • fold(if_empty, f)
  • filter(p)
  • exists(p)
  • contains(elem)
  • to_list()

License

MIT License

Metadata

Release files for scala-option 1.0.2

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

Source distribution (sdist)

Source distribution for scala-option 1.0.2
File Size Uploaded
scala_option-1.0.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scala-option 1.0.2
File Interpreter ABI Platform
scala_option-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / scala_option-1.0.2.tar.gz

Download URL scala_option-1.0.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1aea65aaf7f4dbe8ba67d835dbe25a4dbd6c2da8b041efa51e71b0dd63d2a93a
BLAKE2b-256 checksum
How to use checksums
01f8e1e9b8ab3c393d781e183685156ba9c00342ef5840d3192abbea090706ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / scala_option-1.0.2-py3-none-any.whl

Download URL scala_option-1.0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbada0ec51a5516c93a390f13338396135745d6194d0fb6ef6fdf93bc401050b
BLAKE2b-256 checksum
How to use checksums
c8ffb7dd898636d7c151e87872da994a40cbffc51f88d724399a382830a33159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release 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