Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Union types for python

Project description

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

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)
>>> isinstance(u([1, 2, 3]), u[list])
>>> isinstance(u([1, 2, 3]), (u[tuple], u[str]))

Option Types
.. code-block:: python

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

.. |build status| image::

Project details

Download files

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

Files for uniontypes, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size uniontypes-0.1.0.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page