| Name | funland JSON |
| Version |
0.0.0a0
JSON |
| download |
| home_page | None |
| Summary | Function programming in python |
| upload_time | 2024-08-28 12:51:47 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# UFO 🛸
*uniform functional orchestrators*
Delicious monads and functional programming patterns in python!
[Check out the api docs for reference](https://benrutter.github.io/ufo-tools/index.html)
 
## Project Goals
This library is meant to implement a simple tools for functional programming in python in a way that:
- Can be intergrated quickly/simply with existing code
- Maintains type safety
- Depends only on the standard library
## How to install
```python
pip install ufo-tools
```
## Quick Start
UFO is a library to help with functional programming patterns in python.
It's designed to be very small and get out your way rather than requiring use everywhere.
The library contains two modules: `wrappers` and `containers`. The wrappers are the most simple, so we can start with them.
## Wrappers
Say you have a function that mutates its arguments:
```python
def maximum_of_list_and_also_seven(some_list: list[int]):
"""
Gets the biggest number from a list of ints, but with
seven also included for consideration since its such
a good number.
"""
some_list.append(7)
return max(some_list)
```
The function is simple enough to follow but it's doing something potentially annoying and mutating the `some_list` variables.
For instance:
```python
my_list = [1, 4]
max_item = maximum_of_list_and_also_seven(my_list)
print(max_item) # prints out 7
print(my_list) # [1, 4, 7]
```
Oh no! Our list changed under our feet, that's rude! A lot of the time we don't want this to happen since it can lead to confusing errors. So you could work around it in a bunch of different ways. `ufo_tools` gives you an easy one:
```python
from ufo_tools.wrappers import mutation_free
@mutation_free
def maximum_of_list_and_also_seven(some_list: list[int]):
"""
Gets the biggest number from a list of ints, but with
seven also included for consideration since its such
a good number.
"""
some_list.append(7)
return max(some_list)
```
Phew! Now that function will get passed down deep copies of the `some_list` variable, instead of `some_list` itself, and we can all sleep easy at night.
Even better, the `@mutation_free` wrapper also makes pretty quick reading to know that the function can't mutate it's arguments.
See the documentation for some more examples (like adding in retry logic, error handling and deprecation warnings) but hopefully you get the idea. The wrappers are there as some drop in tools to help you on your way to some nice guarantees when working with python.
## Containers
Containers are a common pattern for functional programming, they let us chain together values nicely.
Say we're building up some kind on string:
```python
def make_exciting(string):
return string + "!!!"
def make_loud(string):
return string.upper()
def say_hello(name):
return f"hello {name}"
name = "Sam"
greeting = say_hello(name)
loud_greeting = make_loud(greeting)
exciting_loud_greeting = make_exciting(loud_greeting)
print(exciting_loud_greeting) # HELLO SAM!!!
```
There's a lot of variables, which in practice aren't ever used, but they *could* get used any time, so we have to keep thinking about them. We can cut down on unnecesary thinking by chaining functions in a big row:
```python
message = make_exciting(make_loud(say_hello("Sam")))
print(message)
```
Phew! Except there's enough brackets to make a lisp programmer cry, and also we're reading in the *opposite order* of the functions being called. `make_exciting` happens last, but we're reading it first which means we're back to extra thinking again! And that's what we were trying to avoid.
Fortunately containers is here to save you:
```python
from ufo.containers import Container
message = (
Container("Sam")
.then(say_hello)
.then(make_loud)
.then(make_exciting)
.unwrap()
)
print(message)
```
That's a little easier to follow. The `unwrap` message probably looks a little strange at the end to you - all it's doing is taking the string back out of the container, so we have just a string to print.
Even better than that, we can actually use containers to do a bunch of busy work for us, say we have a whole bunch of names:
```python
names = ["Lisa", "Bart", "Homer", "Maggie", "Marge"]
greetings = [say_hello(i) for i in names]
loud_greetings = [make_loud(i) for i in greetings]
exciting_loud_greetings = [make_exciting(i) for i in loud_greetings]
```
Oh boy! I'm tired just from typing that example.
Instead, we can use an `Array` container to iterate over things:
```python
from ufo.containers import Array
messages = (
Array("Lisa", "Bart", "Homer", "Maggie", "Marge")
.then(say_hello)
.then(make_loud)
.then(make_exciting)
)
```
This makes things a little easier. The `Array` container also comes with some additional helpers for working with lists like `filter` and `reduce`.
There's containers for handling errors and Nones too - check out the API docs for full details.
Raw data
{
"_id": null,
"home_page": null,
"name": "funland",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/a7/94/1e9f43d542b235bfc436074a23db49c84db52d61ab02e10f1d6ad954b0bb/funland-0.0.0a0.tar.gz",
"platform": null,
"description": "# UFO \ud83d\udef8\n*uniform functional orchestrators*\n\nDelicious monads and functional programming patterns in python!\n\n[Check out the api docs for reference](https://benrutter.github.io/ufo-tools/index.html)\n\n \n\n## Project Goals\n\nThis library is meant to implement a simple tools for functional programming in python in a way that:\n\n- Can be intergrated quickly/simply with existing code\n- Maintains type safety\n- Depends only on the standard library\n\n## How to install\n\n```python\npip install ufo-tools\n```\n\n## Quick Start\n\nUFO is a library to help with functional programming patterns in python.\n\nIt's designed to be very small and get out your way rather than requiring use everywhere.\n\nThe library contains two modules: `wrappers` and `containers`. The wrappers are the most simple, so we can start with them.\n\n## Wrappers\n\nSay you have a function that mutates its arguments:\n\n```python\ndef maximum_of_list_and_also_seven(some_list: list[int]):\n \"\"\"\n Gets the biggest number from a list of ints, but with\n seven also included for consideration since its such\n a good number.\n \"\"\"\n some_list.append(7)\n return max(some_list)\n```\n\nThe function is simple enough to follow but it's doing something potentially annoying and mutating the `some_list` variables.\n\nFor instance:\n\n```python\nmy_list = [1, 4]\n\nmax_item = maximum_of_list_and_also_seven(my_list)\n\nprint(max_item) # prints out 7\n\nprint(my_list) # [1, 4, 7]\n```\n\nOh no! Our list changed under our feet, that's rude! A lot of the time we don't want this to happen since it can lead to confusing errors. So you could work around it in a bunch of different ways. `ufo_tools` gives you an easy one:\n\n```python\nfrom ufo_tools.wrappers import mutation_free\n\n@mutation_free\ndef maximum_of_list_and_also_seven(some_list: list[int]):\n \"\"\"\n Gets the biggest number from a list of ints, but with\n seven also included for consideration since its such\n a good number.\n \"\"\"\n some_list.append(7)\n return max(some_list)\n```\n\nPhew! Now that function will get passed down deep copies of the `some_list` variable, instead of `some_list` itself, and we can all sleep easy at night.\n\nEven better, the `@mutation_free` wrapper also makes pretty quick reading to know that the function can't mutate it's arguments.\n\nSee the documentation for some more examples (like adding in retry logic, error handling and deprecation warnings) but hopefully you get the idea. The wrappers are there as some drop in tools to help you on your way to some nice guarantees when working with python.\n\n\n## Containers\n\nContainers are a common pattern for functional programming, they let us chain together values nicely.\n\nSay we're building up some kind on string:\n\n```python\ndef make_exciting(string):\n return string + \"!!!\"\n\ndef make_loud(string):\n return string.upper()\n\ndef say_hello(name):\n return f\"hello {name}\"\n\nname = \"Sam\"\ngreeting = say_hello(name)\nloud_greeting = make_loud(greeting)\nexciting_loud_greeting = make_exciting(loud_greeting)\n\nprint(exciting_loud_greeting) # HELLO SAM!!!\n```\n\nThere's a lot of variables, which in practice aren't ever used, but they *could* get used any time, so we have to keep thinking about them. We can cut down on unnecesary thinking by chaining functions in a big row:\n\n```python\nmessage = make_exciting(make_loud(say_hello(\"Sam\")))\nprint(message)\n```\n\nPhew! Except there's enough brackets to make a lisp programmer cry, and also we're reading in the *opposite order* of the functions being called. `make_exciting` happens last, but we're reading it first which means we're back to extra thinking again! And that's what we were trying to avoid.\n\nFortunately containers is here to save you:\n\n```python\nfrom ufo.containers import Container\n\nmessage = (\n Container(\"Sam\")\n .then(say_hello)\n .then(make_loud)\n .then(make_exciting)\n .unwrap()\n)\nprint(message)\n```\nThat's a little easier to follow. The `unwrap` message probably looks a little strange at the end to you - all it's doing is taking the string back out of the container, so we have just a string to print.\n\nEven better than that, we can actually use containers to do a bunch of busy work for us, say we have a whole bunch of names:\n\n```python\nnames = [\"Lisa\", \"Bart\", \"Homer\", \"Maggie\", \"Marge\"]\ngreetings = [say_hello(i) for i in names]\nloud_greetings = [make_loud(i) for i in greetings]\nexciting_loud_greetings = [make_exciting(i) for i in loud_greetings]\n```\n\nOh boy! I'm tired just from typing that example.\n\nInstead, we can use an `Array` container to iterate over things:\n\n```python\nfrom ufo.containers import Array\nmessages = (\n Array(\"Lisa\", \"Bart\", \"Homer\", \"Maggie\", \"Marge\")\n .then(say_hello)\n .then(make_loud)\n .then(make_exciting)\n)\n```\nThis makes things a little easier. The `Array` container also comes with some additional helpers for working with lists like `filter` and `reduce`.\n\nThere's containers for handling errors and Nones too - check out the API docs for full details.\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Function programming in python",
"version": "0.0.0a0",
"project_urls": {
"Documentation": "https://benrutter.github.io/ufo-tools/index.html",
"Homepage": "https://benrutter.github.io/ufo-tools/index.html",
"Issues": "https://github.com/benrutter/ufo-tools/issues",
"Repository": "https://github.com/benrutter/ufo-tools"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fe627405cdd92f0807c888a368be1d93f9fd9f60fa2a19b4ce2a34ddbdf730a7",
"md5": "3cb44a5a301ac5452d47f5611f79bd92",
"sha256": "2ea5b47148384124095ef9779cf27755e91f3831a9df31bf4bcdc5cafcec85ee"
},
"downloads": -1,
"filename": "funland-0.0.0a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3cb44a5a301ac5452d47f5611f79bd92",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8068,
"upload_time": "2024-08-28T12:51:46",
"upload_time_iso_8601": "2024-08-28T12:51:46.071266Z",
"url": "https://files.pythonhosted.org/packages/fe/62/7405cdd92f0807c888a368be1d93f9fd9f60fa2a19b4ce2a34ddbdf730a7/funland-0.0.0a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a7941e9f43d542b235bfc436074a23db49c84db52d61ab02e10f1d6ad954b0bb",
"md5": "f9bf19e330f2d642ee2df160d2b82e6a",
"sha256": "1ab998eef4d89211df30ae1bebf96ee7fc899b7cbcfa87cd863602c8aac5706c"
},
"downloads": -1,
"filename": "funland-0.0.0a0.tar.gz",
"has_sig": false,
"md5_digest": "f9bf19e330f2d642ee2df160d2b82e6a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7355,
"upload_time": "2024-08-28T12:51:47",
"upload_time_iso_8601": "2024-08-28T12:51:47.722915Z",
"url": "https://files.pythonhosted.org/packages/a7/94/1e9f43d542b235bfc436074a23db49c84db52d61ab02e10f1d6ad954b0bb/funland-0.0.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-28 12:51:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "benrutter",
"github_project": "ufo-tools",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "funland"
}