opytional


Nameopytional JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/mmore500/opytional
Summaryopytional makes working with values that might be None safer and easier
upload_time2022-02-23 02:32:08
maintainer
docs_urlNone
authorMatthew Andres Moreno
requires_python>=3.6
licenseMIT license
keywords opytional
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ============
opytional
============


.. image:: https://img.shields.io/pypi/v/opytional.svg
        :target: https://pypi.python.org/pypi/opytional

.. image:: https://img.shields.io/travis/mmore500/opytional.svg
        :target: https://travis-ci.com/mmore500/opytional

.. image:: https://readthedocs.org/projects/opytional/badge/?version=latest
        :target: https://opytional.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status




opytional makes working with values that might be None safer and easier


* Free software: MIT license
* Documentation: https://opytional.readthedocs.io.


Inspired by C++'s :code:`std::optional`.


.. code-block:: python3

  import opytional as opyt



  # opyt.or_value
  # provides a fallback value when value is None

  opyt.or_value(None, 'fallback') # returns 'fallback'

  opyt.or_value('value', 'fallback') # returns 'value'



  # opyt.or_else
  # provides a fallback callable when value is None

  opyt.or_else(None, lambda: 'fallback') # returns 'fallback'

  opyt.or_else('value', lambda: 'fallback') # returns 'value'



  # opyt.apply_if
  # applies an operator to value when value is not None

  opyt.apply_if(None, lambda x: x + ' world') # returns None

  opyt.apply_if('hello', lambda x: x + ' world') # returns 'hello world'



  # opyt.apply_if_or_value
  # applies an operator to value when value is not None
  # with a fallback value for when value is None

  opyt.apply_if_or_value(None, lambda x: x + ' world', 'fallback')
  # returns 'fallback'

  opyt.apply_if_or_value('hello', lambda x: x + ' world', 'fallback')
  # returns 'hello world'

  opyt.apply_if_or_value('hello', lambda x: None, 'fallback') # returns None



  # opyt.apply_if_or_else
  # applies an operator to value when value is not None
  # with a fallback callable for when value is None

  opyt.apply_if_or_else(None, lambda x: x + ' world', lambda: 'fallback')
  # returns 'fallback'

  opyt.apply_if_or_value('hello', lambda x: x + ' world', lambda: 'fallback')
  # returns 'hello world'

  opyt.apply_if_or_value('hello', lambda x: None, lambda: 'fallback')
  # returns None


Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

0.1.0 (2022-02-22)
------------------

* First release on PyPI.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mmore500/opytional",
    "name": "opytional",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "opytional",
    "author": "Matthew Andres Moreno",
    "author_email": "m.more500@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8d/87/0d2aa933b3689c57a9e431288d50fb618250c57ccb3aca03a62150733950/opytional-0.1.0.tar.gz",
    "platform": "",
    "description": "============\nopytional\n============\n\n\n.. image:: https://img.shields.io/pypi/v/opytional.svg\n        :target: https://pypi.python.org/pypi/opytional\n\n.. image:: https://img.shields.io/travis/mmore500/opytional.svg\n        :target: https://travis-ci.com/mmore500/opytional\n\n.. image:: https://readthedocs.org/projects/opytional/badge/?version=latest\n        :target: https://opytional.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n\n\n\nopytional makes working with values that might be None safer and easier\n\n\n* Free software: MIT license\n* Documentation: https://opytional.readthedocs.io.\n\n\nInspired by C++'s :code:`std::optional`.\n\n\n.. code-block:: python3\n\n  import opytional as opyt\n\n\n\n  # opyt.or_value\n  # provides a fallback value when value is None\n\n  opyt.or_value(None, 'fallback') # returns 'fallback'\n\n  opyt.or_value('value', 'fallback') # returns 'value'\n\n\n\n  # opyt.or_else\n  # provides a fallback callable when value is None\n\n  opyt.or_else(None, lambda: 'fallback') # returns 'fallback'\n\n  opyt.or_else('value', lambda: 'fallback') # returns 'value'\n\n\n\n  # opyt.apply_if\n  # applies an operator to value when value is not None\n\n  opyt.apply_if(None, lambda x: x + ' world') # returns None\n\n  opyt.apply_if('hello', lambda x: x + ' world') # returns 'hello world'\n\n\n\n  # opyt.apply_if_or_value\n  # applies an operator to value when value is not None\n  # with a fallback value for when value is None\n\n  opyt.apply_if_or_value(None, lambda x: x + ' world', 'fallback')\n  # returns 'fallback'\n\n  opyt.apply_if_or_value('hello', lambda x: x + ' world', 'fallback')\n  # returns 'hello world'\n\n  opyt.apply_if_or_value('hello', lambda x: None, 'fallback') # returns None\n\n\n\n  # opyt.apply_if_or_else\n  # applies an operator to value when value is not None\n  # with a fallback callable for when value is None\n\n  opyt.apply_if_or_else(None, lambda x: x + ' world', lambda: 'fallback')\n  # returns 'fallback'\n\n  opyt.apply_if_or_value('hello', lambda x: x + ' world', lambda: 'fallback')\n  # returns 'hello world'\n\n  opyt.apply_if_or_value('hello', lambda x: None, lambda: 'fallback')\n  # returns None\n\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\n\n=======\nHistory\n=======\n\n0.1.0 (2022-02-22)\n------------------\n\n* First release on PyPI.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "opytional makes working with values that might be None safer and easier",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/mmore500/opytional"
    },
    "split_keywords": [
        "opytional"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28f1d282b5fdecd6b579b7fcc09ea2cb8a69837dd197acfe4a8d0806f5f3f931",
                "md5": "b1017884b362884caa4b7d9d7b315786",
                "sha256": "5504d36d3fa9b466d171336e92a11bde4dae52bf6878f26d539f8b688503f8e4"
            },
            "downloads": -1,
            "filename": "opytional-0.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1017884b362884caa4b7d9d7b315786",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 5754,
            "upload_time": "2022-02-23T02:32:06",
            "upload_time_iso_8601": "2022-02-23T02:32:06.477247Z",
            "url": "https://files.pythonhosted.org/packages/28/f1/d282b5fdecd6b579b7fcc09ea2cb8a69837dd197acfe4a8d0806f5f3f931/opytional-0.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d870d2aa933b3689c57a9e431288d50fb618250c57ccb3aca03a62150733950",
                "md5": "a16c801d831b7a375099b6bb7bbcc94a",
                "sha256": "84eab1deca9fda36e8ed0c5743615f670264c479d73ae4cd5416b4701c927034"
            },
            "downloads": -1,
            "filename": "opytional-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a16c801d831b7a375099b6bb7bbcc94a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11067,
            "upload_time": "2022-02-23T02:32:08",
            "upload_time_iso_8601": "2022-02-23T02:32:08.002599Z",
            "url": "https://files.pythonhosted.org/packages/8d/87/0d2aa933b3689c57a9e431288d50fb618250c57ccb3aca03a62150733950/opytional-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-02-23 02:32:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mmore500",
    "github_project": "opytional",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "opytional"
}
        
Elapsed time: 0.20205s