{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# Functional Python - Scala-like monadic data types\n\n**Functional Python** is a framework which implements Scala-like monadic data types,\nsuch as [Option](https://scala-lang.org/api/2.13.x/scala/Option.html) or [Map](https://docs.scala-lang.org/overviews/collections/maps.html).\n\n## Why?\n##### Method chaining\n```python\n# ToDo: Example\n```\n\n##### Type Safety\n```python\n# ToDo: Example\n```\n\n## Api Description\n### Options\nRepresents optional values.\nInstances of Option are either an instance of Some or the object None.\nOptions are generics of single type parameter.\n\n##### Creating an Option\n```python\nfrom functional.option import *\n\n# Scala-like constructor\nx = Some(4) # Some(4)\ny = Option.empty # None\nz = none # None\n\n# Python-like constructor\nx = Option(4) # Some(4)\ny = Option(None) # None\n```\n\nNote that `None` which is printed **is not** Python `None`\nbut is special object which does not contain any value and equals to `Option(None)`.\n\n##### Getting value of an Option\nOptions implement `.get` property and `.getOrElse(default)` method.\nFirst one checks Option is not empty and either returns value or throws an exception.\nSecond one returns *default* instead of throwing an exception.\n\n```python\nfrom functional.option import *\nx = Some(4) # Some(4)\ny = none # None\n\nx.get # 4\ny.get # raises EmptyOption\n\nx.get_or_else(5) # 4\ny.get_or_else(5) # 5\n\n# .is_defined returns True if Option is not None\nx.is_defined # True\ny.is_defined # False\n\n# .is_empty is the opposite\nx.is_empty # False\ny.is_empty # True\n\n# .non_empty is the same as .is_defined\nx.non_empty # True\ny.non_empty # False\n```\n\nNote that unlike in Scala, this Option's `.get_or_else` is not lazy-evaluated,\nso this code will fail:\n```python\nSome(4).get_or_else(1/0)\n```\n\nTo prevent, it is recommended use python-like accessors (see below).\n\n##### Mapping an Option\nOptions are both functors and monads, meaning they possess `.map()` and `.flat_map()` methods\nwith the following signatures (where object is a type `Option[A]`):\n - `.map(f: A => B): Option[B]` - map value inside an Option.\n - `.flat_map(f: A => Option[B]): Option[B]` - map value inside an Option to an Option.\n\nBoth these methods work only on non-empty options, returning `Option.empty` for otherwise.\n\n```python\nfrom functional.option import *\nx = Some(4) # Some(4)\ny = none # None\nz = Some(6) # Some(6)\n\nx.map(lambda v: v + 2) # Some(6)\ny.map(lambda v: v + 2) # None\nz.map(lambda v: v + 2) # Some(8)\n\nx.flat_map(lambda v: Some(v) if v < 5 else none) # Some(4)\ny.flat_map(lambda v: Some(v) if v < 5 else none) # None\nz.flat_map(lambda v: Some(v) if v < 5 else none) # None\n```\n\n##### Flattening an Option\nSometimes you get an Option which contains Option.\nThere is special property `.flatten` which converts `Option[Option[T]]` into `Option[T]`\n\n```python\n# ToDo: Example\n```\n\n##### Python-style accessors\nOptions support python-like accessors / converters `__bool__`, `__iter__`, `__len__`, and `__enter__/__exit`.\n\n```python\n# ToDo: Example\n```\n\n### Map\n**TODO**\n\n## Plans\n - Test coverage\n - Support Maps (both mutable and immutable)\n - Support Lists (both mutable and immutable)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/Hares/functional-python", "keywords": "", "license": "BSD 2-Clause License", "maintainer": "", "maintainer_email": "", "name": "functional-python", "package_url": "https://pypi.org/project/functional-python/", "platform": "", "project_url": "https://pypi.org/project/functional-python/", "project_urls": { "Homepage": "https://gitlab.com/Hares/functional-python" }, "release_url": "https://pypi.org/project/functional-python/0.0.4/", "requires_dist": [ "dataclasses (>=0.6) ; python_version == \"3.6\"", "html-testRunner (>=1.2) ; extra == 'test'", "html-testRunner (>=1.2) ; extra == 'all'" ], "requires_python": ">=3.6.0", "summary": "Python implementation of Scala-like monadic data types.", "version": "0.0.4" }, "last_serial": 5868993, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "c9784beae3831559f328b6a60b955205", "sha256": "9d8d5638ce636f8bc9a8bf69f0902317af4a0a2b0a11cb5a8fe46ee0450f4414" }, "downloads": -1, "filename": "functional-python-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c9784beae3831559f328b6a60b955205", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 4387, "upload_time": "2019-08-15T01:03:22", "url": "https://files.pythonhosted.org/packages/12/71/abcfb9d94735eaefec28eb086bb04aefe87fcdce102d27c5231517ab2685/functional-python-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "54e975d96d944ace82c809f1c7635a5e", "sha256": "c6f58a2e9875226552bdb86ce2e7ef811cb4be99f4ea389f09b790659e352fae" }, "downloads": -1, "filename": "functional_python-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "54e975d96d944ace82c809f1c7635a5e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 6146, "upload_time": "2019-09-08T23:40:22", "url": "https://files.pythonhosted.org/packages/5e/01/c983a293d773efa67908372b5a2565653046a0dca16ab4350cf9c56882d6/functional_python-0.0.2-py3-none-any.whl" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "0f5259746a8d410ed6416a0d70553f4c", "sha256": "8ed605f653a4ae729cd17c8a7cba586826355d445926984bcf5e88ffbf651ce8" }, "downloads": -1, "filename": "functional_python-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "0f5259746a8d410ed6416a0d70553f4c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 6191, "upload_time": "2019-09-22T05:56:05", "url": "https://files.pythonhosted.org/packages/2a/92/c57929bf00f5109475526ec10483925c5605048b6e9c44bc84c4fbd6862a/functional_python-0.0.3-py3-none-any.whl" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "dd80a211a32e0709a641bead121a622d", "sha256": "a0d86a0c284d4ab6c31f3873874ab1c8c324319cdfe35f1432cacacbcc82ce22" }, "downloads": -1, "filename": "functional_python-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "dd80a211a32e0709a641bead121a622d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 6042, "upload_time": "2019-09-22T12:50:02", "url": "https://files.pythonhosted.org/packages/e1/9f/01051f174620df5394e73e47cb9e76aa618e6e38f2137b7eec627143a350/functional_python-0.0.4-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dd80a211a32e0709a641bead121a622d", "sha256": "a0d86a0c284d4ab6c31f3873874ab1c8c324319cdfe35f1432cacacbcc82ce22" }, "downloads": -1, "filename": "functional_python-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "dd80a211a32e0709a641bead121a622d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 6042, "upload_time": "2019-09-22T12:50:02", "url": "https://files.pythonhosted.org/packages/e1/9f/01051f174620df5394e73e47cb9e76aa618e6e38f2137b7eec627143a350/functional_python-0.0.4-py3-none-any.whl" } ] }