Skip to main content

Real Optional type in python, not @Nullable annotation.

Project description

IceSpringRealOptional

Real Optional type in python, not @Nullable annotation.

Official sites

Features

  • All Java 8 style Optional API support
  • All Generic Type annotation support

Install

  • PyPI: pip install IceSpringRealOptional

Usage

from IceSpringRealOptional.maybe import Maybe

maybe = Maybe.ofNullable("CommonSense")
print("{}: isPresent={}".format(maybe, maybe.isPresent()))
print("{}: value={}".format(maybe, maybe.get()))
maybe.ifPresent(lambda x: print(f"{x} exist"))
print("{}'s length: {}".format(maybe, maybe.map(len)))

empty = Maybe.empty()
print(empty.orElse("{} is empty".format(empty)))
print(empty.orElseGet(lambda: "{} is empty again".format(empty)))

try:
    Maybe.empty().orElseThrow(lambda: RuntimeError("Unlucky"))
except RuntimeError as e:
    print("Runtime error caught: {}".format(e))

Example Output

<Maybe:CommonSense>: isPresent=True
<Maybe:CommonSense>: value=CommonSense
CommonSense exist
<Maybe:CommonSense>'s length: <Maybe:11>
<Maybe:None> is empty
<Maybe:None> is empty again
Runtime error caught: Unlucky

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

IceSpringRealOptional-1.2.4.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

IceSpringRealOptional-1.2.4-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file IceSpringRealOptional-1.2.4.tar.gz.

File metadata

  • Download URL: IceSpringRealOptional-1.2.4.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for IceSpringRealOptional-1.2.4.tar.gz
Algorithm Hash digest
SHA256 41d79e1a33f4391af9a551ab5265fa2da2fee948219f68c719a0854fcce364a0
MD5 fcc9621862bbfa3d208ed4157e81ea8a
BLAKE2b-256 93fcac6d76672a22d82896177189dbe083af5c03c5b8103990dc27901609a065

See more details on using hashes here.

File details

Details for the file IceSpringRealOptional-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: IceSpringRealOptional-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for IceSpringRealOptional-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 700b4f9873c8ec2841979dac6a7b244ab2941c6d47d3f27c16817d204f1a1ade
MD5 a3f82a035f317cc71244d96ecb4268e0
BLAKE2b-256 ccd6a148f5e530bf7d554cbdc1286505ea264fb4e026669d2c6b62eb8bb7a244

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