scala-option


Namescala-option JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryScala like Option type in Python
upload_time2025-01-26 18:10:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords option optional maybe functional
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # scala_option

<!-- Badges: -->
[![python](https://img.shields.io/badge/Python->=_3.12-3776AB.svg?style=flat&logo=python&logoColor=yellow)](https://www.python.org)
![Test Coverage](https://img.shields.io/badge/test_coverage-88%25-green)
![License](https://img.shields.io/badge/License-MIT-blue)

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](#installation)
  - [Requirements](#requirements)
  - [Installing Using PIP](#installing-using-pip)
  - [Building from Source](#building-from-source)
- [Usage](#quick-start)
  - [Quick Start](#quick-start)
  - [Implemented Methods](#implemented-methods)
- [License](#license)

## Installation

### Requirements

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

You can check your python version by running the command:

> Windows:
> ```pwsh
> py --version
> ```
>
> Linux and macOS:
> ```bash
> python3 --version
> ```

### Installing Using PIP

You can install the package by running the command:

```bash
pip install scala_option
```

### Building from Source

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

Next, install the `build` package:

```bash
pip install build
```

Then, build the project by running:

> Windows:
> ```pwsh
> py -m build
> ```
>
> Linux and macOS:
> ```bash
> python3 -m build
> ```


To install the package locally, run:

```bash
pip install -e .
```

## Usage

### Quick Start

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

```py
from scala_option import Option, none, some
```

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

```py
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

Implements some of the most important methods of the Scala `Option`
([documentation](https://dotty.epfl.ch/api/scala/Option.html)).

- `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](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "scala-option",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "option, optional, maybe, functional",
    "author": null,
    "author_email": "Alex Suopanki <alex.suopanki@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/e1/ea/220a58a5929b77fda9d81b2f8dcba4595022ac897e6b21d8036fcb02ab7e/scala_option-1.0.1.tar.gz",
    "platform": null,
    "description": "# scala_option\n\n<!-- Badges: -->\n[![python](https://img.shields.io/badge/Python->=_3.12-3776AB.svg?style=flat&logo=python&logoColor=yellow)](https://www.python.org)\n![Test Coverage](https://img.shields.io/badge/test_coverage-88%25-green)\n![License](https://img.shields.io/badge/License-MIT-blue)\n\nScala like `Option` type in Python.\n\nImplements the child classes `None` and `Some`, but renamed to `none` and\n`some`, since `None` is a built-in type in Python.\n\n## Table of Contents\n\n- [Installation](#installation)\n  - [Requirements](#requirements)\n  - [Installing Using PIP](#installing-using-pip)\n  - [Building from Source](#building-from-source)\n- [Usage](#quick-start)\n  - [Quick Start](#quick-start)\n  - [Implemented Methods](#implemented-methods)\n- [License](#license)\n\n## Installation\n\n### Requirements\n\nThis library requires Python 3.12.0 or newer, because it uses the latest syntax\nfor generics, introduced in Python 3.12.\n\nYou can check your python version by running the command:\n\n> Windows:\n> ```pwsh\n> py --version\n> ```\n>\n> Linux and macOS:\n> ```bash\n> python3 --version\n> ```\n\n### Installing Using PIP\n\nYou can install the package by running the command:\n\n```bash\npip install scala_option\n```\n\n### Building from Source\n\nFirst, clone the repository or download source code from the latest release.\n\nNext, install the `build` package:\n\n```bash\npip install build\n```\n\nThen, build the project by running:\n\n> Windows:\n> ```pwsh\n> py -m build\n> ```\n>\n> Linux and macOS:\n> ```bash\n> python3 -m build\n> ```\n\n\nTo install the package locally, run:\n\n```bash\npip install -e .\n```\n\n## Usage\n\n### Quick Start\n\nOnce you have installed the package (see [Installation](#installation)), you\njust need to add the import statement:\n\n```py\nfrom scala_option import Option, none, some\n```\n\nThen you can begin using the `Option` type. Here's a little example:\n\n```py\nimport random\nfrom scala_option import Option, none, some\n\ndef fivety_fivety() -> Option[int]:\n  if random.random() <= 0.5:\n    return some(1)\n  else:\n    return none\n\ndef print_option(option: Option) -> None:\n  if option.is_empty():\n    print(\"You got nothing!\")\n  else:\n    print(f\"You got something: {option.get()}\")\n```\n\n### Implemented Methods\n\nImplements some of the most important methods of the Scala `Option`\n([documentation](https://dotty.epfl.ch/api/scala/Option.html)).\n\n- `get()`\n- `is_empty()`\n- `non_empty()`\n- `get_or_else(default)`\n- `or_else(alternative)`\n- `map(f)`\n- `flat_map(f)`\n- `fold(if_empty, f)`\n- `filter(p)`\n- `exists(p)`\n- `contains(elem)`\n- `to_list()`\n\n## License\n\n[MIT License](LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Scala like Option type in Python",
    "version": "1.0.1",
    "project_urls": {
        "Repository": "https://github.com/Suopunki/scala_option"
    },
    "split_keywords": [
        "option",
        " optional",
        " maybe",
        " functional"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "05beb6461b9c258026a3c5dd8fece95957bce59473b9b95ba703b05983128970",
                "md5": "83dbf2c5198992de3f268e695a4112b6",
                "sha256": "e02953b395951dfbeab72dbf0baf40661457a844319a48dcf88b5520c991c1da"
            },
            "downloads": -1,
            "filename": "scala_option-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "83dbf2c5198992de3f268e695a4112b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 5764,
            "upload_time": "2025-01-26T18:10:21",
            "upload_time_iso_8601": "2025-01-26T18:10:21.444803Z",
            "url": "https://files.pythonhosted.org/packages/05/be/b6461b9c258026a3c5dd8fece95957bce59473b9b95ba703b05983128970/scala_option-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e1ea220a58a5929b77fda9d81b2f8dcba4595022ac897e6b21d8036fcb02ab7e",
                "md5": "6df18c2aad5cd3eb134aedd8cc1a37ee",
                "sha256": "a42d81ddb57b712c8e878f9b4be1288ebb3b1a1fe84e2c105415a460ed5a22c1"
            },
            "downloads": -1,
            "filename": "scala_option-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6df18c2aad5cd3eb134aedd8cc1a37ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 4595,
            "upload_time": "2025-01-26T18:10:23",
            "upload_time_iso_8601": "2025-01-26T18:10:23.297157Z",
            "url": "https://files.pythonhosted.org/packages/e1/ea/220a58a5929b77fda9d81b2f8dcba4595022ac897e6b21d8036fcb02ab7e/scala_option-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-26 18:10:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Suopunki",
    "github_project": "scala_option",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "scala-option"
}
        
Elapsed time: 1.29408s