Skip to main content
``uniontypes 0.1``
============

|build status|

Union types For python.

These appear other languages like Haskell (``Either``) and
Scala (``Union`` or ``\/``).

This extends to any arbirary set of types.


Examples
--------
Creating a union type
~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

>>> from uniontypes import Union
>>> u = Union[list, tuple, str]
>>> u
<class 'uniontypes.Union[list, tuple, str]'>

Creating boxed values
~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

>>> u([1, 2, 3])
Union[list, tuple, str][list] [1, 2, 3]
>>> u((1, 2, 3))
Union[list, tuple, str][tuple] (1, 2, 3)
>>> u('123')
Union[list, tuple, str][str] '123'

Accessing the inner wrapper types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

>>> u[list]
<class 'uniontypes.Union[list, tuple, str][list]'>
>>> u[tuple]
<class 'uniontypes.Union[list, tuple, str][tuple]'>
>>> u[str]
<class 'uniontypes.Union[list, tuple, str][str]'>

Class heirarchy
~~~~~~~~~~~~~~~
.. code-block:: python

>>> isinstance(u([1, 2, 3]), u)
True
>>> isinstance(u([1, 2, 3]), u[list])
True
>>> isinstance(u([1, 2, 3]), (u[tuple], u[str]))
False

Option Types
------------
.. code-block:: python

>>> from uniontypes import Option
>>> oint = Option[int]
>>> oint
<class 'uniontypes.Option[int]'>
>>> oint(1)
Option[int] 1
>>> oint(None)
Nothing
>>> oint(None) is oint.nothing
True


.. |build status| image:: https://travis-ci.org/llllllllll/uniontypes.svg?branch=master
:target: https://travis-ci.org/llllllllll/uniontypes

Download files

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

Source Distribution

uniontypes-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: uniontypes-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for uniontypes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 671dec4cbe1a1af6506f24a19f83b589aaa6ed1a78704e4bca7bb4b529e3e8a3
MD5 50be5600e90eded6ce444c877223f486
BLAKE2b-256 0d09a2b47ceb2b926d6184c63cc60ca45b2c7edfbac1e9ac9a05b1d415c332d9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 file

0.0.1

1 file

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