{"id":18263070,"url":"https://github.com/dry-python/functional-jargon-python","last_synced_at":"2025-04-09T01:26:00.628Z","repository":{"id":49931978,"uuid":"285220055","full_name":"dry-python/functional-jargon-python","owner":"dry-python","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-07T14:27:52.000Z","size":231,"stargazers_count":69,"open_issues_count":18,"forks_count":5,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T18:49:58.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dry-python.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"dry-python","open_collective":"dry-python"}},"created_at":"2020-08-05T07:55:34.000Z","updated_at":"2024-10-12T04:37:30.000Z","dependencies_parsed_at":"2022-08-31T15:10:52.540Z","dependency_job_id":"fb996412-fce6-4876-a6fd-e1636f76d1b5","html_url":"https://github.com/dry-python/functional-jargon-python","commit_stats":{"total_commits":65,"total_committers":4,"mean_commits":16.25,"dds":0.5076923076923077,"last_synced_commit":"3d21895a1ee752b4a9c0248977316e8924ca99fc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Ffunctional-jargon-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Ffunctional-jargon-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Ffunctional-jargon-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Ffunctional-jargon-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dry-python","download_url":"https://codeload.github.com/dry-python/functional-jargon-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713356,"owners_count":20983696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:09:47.838Z","updated_at":"2025-04-09T01:26:00.601Z","avatar_url":"https://github.com/dry-python.png","language":null,"readme":"# Functional Programming Jargon\n\n[![Build Status](https://github.com/dry-python/functional-jargon-python/workflows/test/badge.svg?event=push)](https://github.com/dry-python/functional-jargon-python/actions?query=workflow%3Atest)\n\nFunctional programming (FP) provides many advantages, and its popularity has been increasing as a result. However, each programming paradigm comes with its own unique jargon and FP is no exception. By providing a glossary, we hope to make learning FP easier.\n\nThis is a fork of [Functional Programming Jargon](https://github.com/jmesyou/functional-programming-jargon).\n\nThis document is WIP and pull requests are welcome!\n\n__Table of Contents__\n\u003c!-- RM(noparent,notop) --\u003e\n\n* [Side effects](#side-effects)\n* [Purity](#purity)\n* [Idempotent](#idempotent)\n* [Arity](#arity)\n* [IO](#io)\n* [Higher-Order Functions (HOF)](#higher-order-functions-hof)\n* [Closure (TODO)](#closure-todo)\n* [Partial Application](#partial-application)\n* [Currying](#currying)\n* [Function Composition](#function-composition)\n* [Continuation (TODO)](#continuation-todo)\n* [Point-Free Style](#point-free-style)\n* [Predicate](#predicate)\n* [Contracts (TODO)](#contracts-todo)\n* [Category (TODO)](#category-todo)\n* [Value (TODO)](#value-todo)\n* [Constant (TODO)](#constant-todo)\n* [Lift (TODO)](#lift-todo)\n* [Referential Transparency (TODO)](#referential-transparency-todo)\n* [Equational Reasoning (TODO)](#equational-reasoning-todo)\n* [Lambda (TODO)](#lambda-todo)\n* [Lambda Calculus (TODO)](#lambda-calculus-todo)\n* [Lazy evaluation (TODO)](#lazy-evaluation-todo)\n* [Functor](#functor)\n* [Applicative Functor](#applicative-functor)\n* [Monoid](#monoid)\n* [Monad (TODO)](#monad-todo)\n* [Comonad (TODO)](#comonad-todo)\n* [Morphism (TODO)](#morphism-todo)\n  * [Endomorphism (TODO)](#endomorphism-todo)\n  * [Isomorphism (TODO)](#isomorphism-todo)\n  * [Homomorphism (TODO)](#homomorphism-todo)\n  * [Catamorphism (TODO)](#catamorphism-todo)\n  * [Anamorphism (TODO)](#anamorphism-todo)\n  * [Hylomorphism (TODO)](#hylomorphism-todo)\n  * [Paramorphism (TODO)](#paramorphism-todo)\n  * [Apomorphism (TODO)](#apomorphism-todo)\n* [Setoid (TODO)](#setoid-todo)\n* [Semigroup (TODO)](#semigroup-todo)\n* [Foldable (TODO)](#foldable-todo)\n* [Lens (TODO)](#lens-todo)\n* [Type Signatures (TODO)](#type-signatures-todo)\n* [Algebraic data type (TODO)](#algebraic-data-type-todo)\n  * [Sum type (TODO)](#sum-type-todo)\n  * [Product type (TODO)](#product-type-todo)\n* [Option (TODO)](#option-todo)\n* [Function (TODO)](#function-todo)\n* [Partial function (TODO)](#partial-function-todo)\n\n\n\u003c!-- /RM --\u003e\n\n\n## Side effects\n\nA function or expression is said to have a side effect if apart from returning a value, \nit interacts with (reads from or writes to) external mutable state:\n\n```python\n\u003e\u003e\u003e print('This is a side effect!')\nThis is a side effect!\n\u003e\u003e\u003e\n```\n\nOr:\n\n```python\n\u003e\u003e\u003e numbers = []\n\u003e\u003e\u003e numbers.append(1)  # mutates the `numbers` array\n\u003e\u003e\u003e\n```\n\n\n## Purity\n\nA function is pure if the return value is only determined by its\ninput values, and does not produce any side effects.\n\nThis function is pure:\n\n```python\n\u003e\u003e\u003e def add(first: int, second: int) -\u003e int:\n...    return first + second\n\u003e\u003e\u003e\n```\n\nAs opposed to each of the following:\n\n```python\n\u003e\u003e\u003e def add_and_log(first: int, second: int) -\u003e int:\n...    print('Sum is:', first + second)  # print is a side effect\n...    return first + second\n\u003e\u003e\u003e\n```\n\n\n## Idempotent\n\nA function is idempotent if reapplying it to its result does not produce a different result:\n\n```python\n\u003e\u003e\u003e assert sorted([2, 1]) == [1, 2]\n\u003e\u003e\u003e assert sorted(sorted([2, 1])) == [1, 2]\n\u003e\u003e\u003e assert sorted(sorted(sorted([2, 1]))) == [1, 2]\n\u003e\u003e\u003e\n```\n\nOr:\n\n```python\n\u003e\u003e\u003e assert abs(abs(abs(-1))) == abs(-1)\n\u003e\u003e\u003e\n```\n\n\n## Arity\n\nThe number of arguments a function takes. From words like unary, binary, ternary, etc. This word has the distinction of being composed of two suffixes, \"-ary\" and \"-ity\". Addition, for example, takes two arguments, and so it is defined as a binary function or a function with an arity of two. Such a function may sometimes be called \"dyadic\" by people who prefer Greek roots to Latin. Likewise, a function that takes a variable number of arguments is called \"variadic,\" whereas a binary function must be given two and only two arguments, currying and partial application notwithstanding.\n\nWe can use the `inspect` module to know the arity of a function, see the example below:\n\n```python\n\u003e\u003e\u003e from inspect import signature\n\n\u003e\u003e\u003e def multiply(number_one: int, number_two: int) -\u003e int:  # arity 2\n...     return number_one * number_two\n\n\u003e\u003e\u003e assert len(signature(multiply).parameters) == 2\n\u003e\u003e\u003e\n```\n\n### Arity Distinctions\n\n#### Minimum Arity and Maximum Arity\n\nThe __minimum arity__ is the smallest number of arguments the function expects to work, the __maximum arity__ is the largest number of arguments function can take. Generally, these numbers are different when our function has default parameter values.\n\n```python\n\u003e\u003e\u003e from inspect import getfullargspec\n\u003e\u003e\u003e from typing import Any\n\n\u003e\u003e\u003e def example(a: Any, b: Any, c: Any = None) -\u003e None:  # mim arity: 2 | max arity: 3\n...     pass\n\n\u003e\u003e\u003e example_args_spec = getfullargspec(example)\n\u003e\u003e\u003e max_arity = len(example_args_spec.args)\n\u003e\u003e\u003e min_arity = max_arity - len(example_args_spec.defaults)\n\n\u003e\u003e\u003e assert max_arity == 3\n\u003e\u003e\u003e assert min_arity == 2\n\u003e\u003e\u003e\n```\n\n#### Fixed Arity and Variable Arity\n\nA function has __fixed arity__ when you have to call it with the same number of arguments as the number of its parameters and a function has __variable arity__ when you can call it with variable number of arguments, like functions with default parameters values.\n\n```python\n\u003e\u003e\u003e from typing import Any\n\n\u003e\u003e\u003e def fixed_arity(a: Any, b: Any) -\u003e None:  # we have to call with 2 arguments\n...     pass\n\n\u003e\u003e\u003e def variable_arity(a: Any, b: Any = None) -\u003e None:  # we can call with 1 or 2 arguments\n...     pass\n\u003e\u003e\u003e\n```\n\n#### Definitive Arity and Indefinite Arity\n\nWhen a function can receive a finite number of arguments it has __definitive arity__, otherwise if the function can receive an undefined number of arguments it has __indefinite arity__. We can reproduce the __indefinite arity__ using Python _*args_ and _**kwargs_, see the example below:\n\n```python\n\u003e\u003e\u003e from typing import Any\n\n\u003e\u003e\u003e def definitive_arity(a: Any, b: Any = None) -\u003e None: # we can call just with 1 or 2 arguments\n...     pass\n\n\u003e\u003e\u003e def indefinite_arity(*args: Any, **kwargs: Any) -\u003e None: # we can call with how many arguments we want\n...     pass\n\u003e\u003e\u003e\n```\n\n### Arguments vs Parameters\n\nThere is a little difference between __arguments__ and __parameters__:\n\n* __arguments__: are the values that are passed to a function\n* __parameters__: are the variables in the function definition\n\n\n## Higher-Order Functions (HOF)\n\nA function that takes a function as an argument and/or returns a function, basically we can treat functions as a value.\nIn Python every function/method can be a Higher-Order Function.\n\nThe functions like `reduce`, `map` and `filter` are good examples of __HOF__, they receive a function as their first argument.\n```python\n\u003e\u003e\u003e from functools import reduce\n\n\u003e\u003e\u003e reduce(lambda accumulator, number: accumulator + number, [1, 2, 3])\n6\n\u003e\u003e\u003e\n```\n\nWe can create our own __HOF__, see the example below:\n\n```python\n\u003e\u003e\u003e from typing import Callable, TypeVar\n\n\u003e\u003e\u003e _ValueType = TypeVar('_ValueType')\n\u003e\u003e\u003e _ReturnType = TypeVar('_ReturnType')\n\n\u003e\u003e\u003e def get_transform_function() -\u003e Callable[[str], int]:\n...     return int\n\n\u003e\u003e\u003e def transform(\n...     transform_function: Callable[[_ValueType], _ReturnType],\n...     value_to_transform: _ValueType,\n... ) -\u003e _ReturnType:\n...     return transform_function(value_to_transform)\n\n\u003e\u003e\u003e transform_function = get_transform_function()\n\u003e\u003e\u003e assert transform(transform_function, '42') == 42\n\u003e\u003e\u003e\n```\n\n\n## IO\n\nIO basically means Input/Output, but it is widely used to just tell that a function is impure.\n\nWe have a special type (``IO``) and a decorator (``@impure``) to do that in Python:\n\n```python\n\u003e\u003e\u003e import random\n\u003e\u003e\u003e from returns.io import IO, impure\n\n\u003e\u003e\u003e @impure\n... def get_random_number() -\u003e int:\n...     return random.randint(0, 100)\n\n\u003e\u003e\u003e assert isinstance(get_random_number(), IO)\n\u003e\u003e\u003e\n```\n\n__Further reading__:\n* [`IO` and `@impure` docs](https://returns.readthedocs.io/en/latest/pages/io.html)\n\n\n## Closure (TODO)\n\nA closure is a way of accessing a variable outside its scope.\nFormally, a closure is a technique for implementing lexically scoped named binding. It is a way of storing a function with an environment.\n\nA closure is a scope which captures local variables of a function for access even after the execution has moved out of the block in which it is defined.\nie. they allow referencing a scope after the block in which the variables were declared has finished executing.\n\n\n```python\n# TODO\n```\n\nLexical scoping is the reason why it is able to find the values of x and add - the private variables of the parent which has finished executing. This value is called a Closure.\n\nThe stack along with the lexical scope of the function is stored in form of reference to the parent. This prevents the closure and the underlying variables from being garbage collected(since there is at least one live reference to it).\n\nLambda Vs Closure: A lambda is essentially a function that is defined inline rather than the standard method of declaring functions. Lambdas can frequently be passed around as objects.\n\nA closure is a function that encloses its surrounding state by referencing fields external to its body. The enclosed state remains across invocations of the closure.\n\n__Further reading/Sources__\n* [Lambda Vs Closure](http://stackoverflow.com/questions/220658/what-is-the-difference-between-a-closure-and-a-lambda)\n* [JavaScript Closures highly voted discussion](http://stackoverflow.com/questions/111102/how-do-javascript-closures-work)\n\n\n## Partial Application\n\nPartially applying a function means creating a new function by pre-filling some of the arguments to the original function.\nYou can also use `functools.partial` or `returns.curry.partial` to partially apply a function in Python:\n\n```python\n\u003e\u003e\u003e from returns.curry import partial\n\n\u003e\u003e\u003e def takes_three_arguments(arg1: int, arg2: int, arg3: int) -\u003e int:\n...     return arg1 + arg2 + arg3\n\n\u003e\u003e\u003e assert partial(takes_three_arguments, 1, 2)(3) == 6\n\u003e\u003e\u003e assert partial(takes_three_arguments, 1)(2, 3) == 6\n\u003e\u003e\u003e assert partial(takes_three_arguments, 1, 2, 3)() == 6\n\u003e\u003e\u003e\n```\n\nThe difference between `returns.curry.partial` and `functools.partial` \nis in how types are infered:\n\n```python\nimport functools\n\nreveal_type(functools.partial(takes_three_arguments, 1))\n# Revealed type is 'functools.partial[builtins.int*]'\n\nreveal_type(partial(takes_three_arguments, 1))\n# Revealed type is 'def (arg2: builtins.int, arg3: builtins.int) -\u003e builtins.int'\n```\n\nPartial application helps create simpler functions from more complex ones by baking in data when you have it. [Curried](#currying) functions are automatically partially applied.\n\n__Further reading__\n* [`@curry` docs](https://returns.readthedocs.io/en/latest/pages/curry.html#partial)\n* [`functools` docs](https://docs.python.org/3/library/functools.html#functools.partial)\n\n\n## Currying\n\nThe process of converting a function that takes multiple arguments into a function that takes them one at a time.\n\nEach time the function is called it only accepts one argument and returns a function that takes one argument until all arguments are passed.\n\n```python\n\u003e\u003e\u003e from returns.curry import curry\n\n\u003e\u003e\u003e @curry\n... def takes_three_args(a: int, b: int, c: int) -\u003e int:\n...     return a + b + c\n\n\u003e\u003e\u003e assert takes_three_args(1)(2)(3) == 6\n\u003e\u003e\u003e\n```\n\nSome implementations of curried functions \ncan also take several of arguments instead of just a single argument:\n\n```python\n\u003e\u003e\u003e assert takes_three_args(1, 2)(3) == 6\n\u003e\u003e\u003e assert takes_three_args(1)(2, 3) == 6\n\u003e\u003e\u003e assert takes_three_args(1, 2, 3) == 6\n\u003e\u003e\u003e\n```\n\nLet's see what type `takes_three_args` has to get a better understanding of its features:\n\n```python\nreveal_type(takes_three_args)\n\n# Revealed type is:\n# Overload(\n#   def (a: builtins.int) -\u003e Overload(\n#     def (b: builtins.int, c: builtins.int) -\u003e builtins.int, \n#     def (b: builtins.int) -\u003e def (c: builtins.int) -\u003e builtins.int\n#   ), \n#   def (a: builtins.int, b: builtins.int) -\u003e def (c: builtins.int) -\u003e builtins.int, \n#   def (a: builtins.int, b: builtins.int, c: builtins.int) -\u003e builtins.int\n# )'\n```\n\n__Further reading__\n* [`@curry` docs](https://returns.readthedocs.io/en/latest/pages/curry.html#id3)\n* [Favoring Curry](http://fr.umio.us/favoring-curry/)\n* [Hey Underscore, You're Doing It Wrong!](https://www.youtube.com/watch?v=m3svKOdZijA)\n\n\n## Function Composition\n\nFor example, you can compose `abs` and `int` functions like so:\n\n```python\n\u003e\u003e\u003e assert abs(int('-1')) == 1\n\u003e\u003e\u003e\n```\n\nYou can also create a third function \nthat will have an input of the first one and an output of the second one:\n\n```python\n\u003e\u003e\u003e from typing import Callable, TypeVar\n\n\u003e\u003e\u003e _FirstType = TypeVar('_FirstType')\n\u003e\u003e\u003e _SecondType = TypeVar('_SecondType')\n\u003e\u003e\u003e _ThirdType = TypeVar('_ThirdType')\n\n\u003e\u003e\u003e def compose(\n...     first: Callable[[_FirstType], _SecondType],\n...     second: Callable[[_SecondType], _ThirdType],\n... ) -\u003e Callable[[_FirstType], _ThirdType]:\n...     return lambda argument: second(first(argument))\n\n\u003e\u003e\u003e assert compose(int, abs)('-1') == 1\n\u003e\u003e\u003e\n```\n\nWe already have this functions defined as `returns.functions.compose`!\n\n```python\n\u003e\u003e\u003e from returns.functions import compose\n\u003e\u003e\u003e assert compose(bool, str)([]) == 'False'\n\u003e\u003e\u003e\n```\n\n__Further reading__\n* [`compose` docs](https://returns.readthedocs.io/en/latest/pages/functions.html#compose)\n\n\n## Continuation (TODO)\n\nAt any given point in a program, the part of the code that's yet to be executed is known as a continuation.\n\n```python\n# TODO\n```\n\nContinuations are often seen in asynchronous programming when the program needs to wait to receive data before it can continue. The response is often passed off to the rest of the program, which is the continuation, once it's been received.\n\n```python\n# TODO\n```\n\n\n## Point-Free Style\n\nPoint-Free is a style of writting code without using any intermediate variables.\n\nBasically, you will end up with long chains of direct function calls.\nThis style usually requires [currying](#currying) or other [Higher-Order functions](#higher-order-functions-hof). \nThis technique is also sometimes called \"Tacit programming\".\n\nThe most common example of Point-Free programming style is Unix with pipes:\n\n```bash\nps aux | grep [k]de | gawk '{ print $2 }'\n```\n\nIt also works for Python, let's say you have this function composition:\n\n```python\n\u003e\u003e\u003e str(bool(abs(-1)))\n'True'\n\u003e\u003e\u003e\n```\n\nIt might be problematic method methods on the first sight, because you need an instance to call a method on.\nBut, you can always use HOF to fix that and compose normally:\n\n```python\n\u003e\u003e\u003e from returns.pipeline import flow\n\u003e\u003e\u003e from returns.pointfree import map_\n\u003e\u003e\u003e from returns.result import Success\n\n\u003e\u003e\u003e assert flow(\n...     Success(-2),\n...     map_(abs),\n...     map_(range),\n...     map_(list),\n... ) == Success([0, 1])\n\u003e\u003e\u003e\n```\n\n__Further reading:__\n* [Pointfree docs](https://returns.readthedocs.io/en/latest/pages/pointfree.html)\n\n\n## Predicate\n\nA predicate is a function that returns true or false for a given value.\nSo, basically a predicate is an alias for `Callable[[_ValueType], bool]`.\n\nIt is very useful when working with `if`, `all`, `any`, etc.\n\n```python\n\u003e\u003e\u003e def is_long(item: str) -\u003e bool:\n...     return len(item) \u003e 3\n\n\u003e\u003e\u003e assert all(is_long(item) for item in ['1234', 'abcd'])\n\u003e\u003e\u003e\n```\n\n__Futher reading__\n* [Predicate logic](https://en.wikipedia.org/wiki/Predicate_functor_logic)\n* [`cond` docs](https://returns.readthedocs.io/en/latest/pages/pointfree.html#cond)\n\n\n## Contracts (TODO)\n\nA contract specifies the obligations and guarantees of the behavior from a function or expression at runtime. This acts as a set of rules that are expected from the input and output of a function or expression, and errors are generally reported whenever a contract is violated.\n\n```python\n# TODO\n```\n\n## Category (TODO)\n\nA category in category theory is a collection of objects and morphisms between them. In programming, typically types\nact as the objects and functions as morphisms.\n\nTo be a valid category 3 rules must be met:\n\n1. There must be an identity morphism that maps an object to itself.\n    Where `a` is an object in some category,\n    there must be a function from `a -\u003e a`.\n2. Morphisms must compose.\n    Where `a`, `b`, and `c` are objects in some category,\n    and `f` is a morphism from `a -\u003e b`, and `g` is a morphism from `b -\u003e c`;\n    `g(f(x))` must be equivalent to `(g • f)(x)`.\n3. Composition must be associative\n    `f • (g • h)` is the same as `(f • g) • h`\n\nSince these rules govern composition at very abstract level, category theory is great at uncovering new ways of composing things.\n\n__Further reading__\n\n* [Category Theory for Programmers](https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/)\n\n## Value (TODO)\n\nAnything that can be assigned to a variable.\n\n```python\n# TODO\n```\n\n## Constant (TODO)\n\nA variable that cannot be reassigned once defined.\n\n```python\n# TODO\n```\n\nConstants are [referentially transparent](#referential-transparency-todo). That is, they can be replaced with the values that they represent without affecting the result.\n\n```python\n# TODO\n```\n\n## Lift (TODO)\n\nLifting is when you take a value and put it into an object like a [Functor](#functor). If you lift a function into an [Applicative Functor](#applicative-functor) then you can make it work on values that are also in that functor.\n\nSome implementations have a function called `lift`, or `liftA2` to make it easier to run functions on functors.\n\n```python\n# TODO\n```\n\nLifting a one-argument function and applying it does the same thing as `map`.\n\n```python\n# TODO\n```\n\n\n## Referential Transparency (TODO)\n\nAn expression that can be replaced with its value without changing the\nbehavior of the program is said to be referentially transparent.\n\nSay we have function greet:\n\n```python\n# TODO\n```\n\n## Equational Reasoning (TODO)\n\nWhen an application is composed of expressions and devoid of side effects, truths about the system can be derived from the parts.\n\n## Lambda (TODO)\n\nAn anonymous function that can be treated like a value.\n\n```python \ndef f(a):\n  return a + 1\n\nlambda a: a + 1\n```\nLambdas are often passed as arguments to Higher-Order functions.\n\n```python\nList([1, 2]).map(lambda x: x + 1) # [2, 3]\n```\n\nYou can assign a lambda to a variable.\n\n```python\nadd1 = lambda a: a + 1\n```\n\n## Lambda Calculus (TODO)\n\nA branch of mathematics that uses functions to create a [universal model of computation](https://en.wikipedia.org/wiki/Lambda_calculus).\n\n## Lazy evaluation (TODO)\n\nLazy evaluation is a call-by-need evaluation mechanism that delays the evaluation of an expression until its value is needed. In functional languages, this allows for structures like infinite lists, which would not normally be available in an imperative language where the sequencing of commands is significant.\n\n```python\n# TODO\n```\n\n## Functor\n\nAn object that implements a `map` method which, while running over each value in the object to produce a new object, adheres to two rules:\n\n__Identity law__\n\n```python\nfunctor.map(lambda x: x) == functor\n```\n\n__Associative law__\n\n```python\nfunctor.map(compose(f, g)) == functor.map(g).map(f)\n```\n\nSometimes `Functor` can be called `Mappable` to its `.map` method.\nYou can have a look at the real-life [`Functor` interface](https://github.com/dry-python/returns/blob/master/returns/interfaces/mappable.py):\n\n```python\n\u003e\u003e\u003e from typing import Callable, TypeVar\n\u003e\u003e\u003e from returns.interfaces.mappable import Mappable1 as Functor\n\u003e\u003e\u003e from returns.primitives.hkt import SupportsKind1\n\n\u003e\u003e\u003e _FirstType = TypeVar('_FirstType')\n\u003e\u003e\u003e _NewFirstType = TypeVar('_NewFirstType')\n\n\u003e\u003e\u003e class Box(SupportsKind1['Box', _FirstType], Functor[_FirstType]):\n...     def __init__(self, inner_value: _FirstType) -\u003e None:\n...         self._inner_value = inner_value\n...\n...     def map(\n...         self,\n...         function: Callable[[_FirstType], _NewFirstType],\n...     ) -\u003e 'Box[_NewFirstType]':\n...         return Box(function(self._inner_value))\n...\n...     def __eq__(self, other) -\u003e bool:\n...         return type(other) == type(self) and self._inner_value == other._inner_value\n\n\u003e\u003e\u003e assert Box(-5).map(abs) == Box(5)\n\u003e\u003e\u003e\n```\n\n__Further reading:__\n\n- [Functor interface docs](https://returns.readthedocs.io/en/latest/pages/interfaces.html#mappable)\n\n\n## Applicative Functor\n\nAn Applicative Functor is an object with `apply` and `.from_value` methods:\n- `.apply` applies a function in the object to a value in another object of the same type. Somethimes this method is also called `ap`\n- `.from_value` creates a new Applicative Functor from a pure value. Sometimes this method is also called `pure`\n\nAll Applicative Functors must also follow [a bunch of laws](https://returns.readthedocs.io/en/latest/pages/interfaces.html#applicative).\n\n__Further reading:__\n\n- [`Applicative Functor` interface docs](https://github.com/dry-python/returns/blob/master/returns/interfaces/applicative.py)\n\n\n## Monoid\n\nAn object with a function that \"combines\" that object with another of the same type\nand an \"empty\" value, which can be added with no effect.\n\nOne simple monoid is the addition of numbers \n(with `__add__` as an addition function and `0` as an empty element):\n\n```python\n\u003e\u003e\u003e assert 1 + 1 + 0 == 2\n\u003e\u003e\u003e\n```\n\nTuples, lists, and strings are also monoids:\n\n```python\n\u003e\u003e\u003e assert (1,) + (2,) + () == (1, 2)\n\u003e\u003e\u003e assert [1] + [2] + [] == [1, 2]\n\u003e\u003e\u003e assert 'a' + 'b' + '' == 'ab'\n\u003e\u003e\u003e\n```\n\n\n## Monad (TODO)\n\nA monad is an [Applicative Functor](#applicative-functor) with `bind` method. \n`bind` is like [`map`](#functor) except it un-nests the resulting nested object.\n\n```python\n# TODO\n```\n\n`of` is also known as `return` in other functional languages.\n`chain` is also known as `flatmap` and `bind` in other languages.\n\n## Comonad (TODO)\n\nAn object that has `extract` and `extend` functions.\n\n```python\n# TODO\n```\n\n## Morphism (TODO)\n\nA transformation function.\n\n### Endomorphism (TODO)\n\nA function where the input type is the same as the output.\n\n```python\n# uppercase :: String -\u003e String\nuppercase = lambda s: s.upper() \n\n# decrement :: Number -\u003e Number\ndecrement = lambda x: x - 1\n```\n\n### Isomorphism (TODO)\n\nA pair of transformations between 2 types of objects that is structural in nature and no data is lost.\n\n```python\n# TODO\n```\n\n### Homomorphism (TODO)\n\nA homomorphism is just a structure preserving map. In fact, a functor is just a homomorphism between categories as it preserves the original category's structure under the mapping.\n\n```python\n# TODO\n```\n\n### Catamorphism (TODO)\n\nA `reduce_right` function that applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.\n\n```python\n# TODO\n```\n\n### Anamorphism (TODO)\n\nAn `unfold` function. An `unfold` is the opposite of `fold` (`reduce`). It generates a list from a single value.\n\n```python\n# TODO\n```\n\n### Hylomorphism (TODO)\n\nThe combination of anamorphism and catamorphism.\n\n### Paramorphism (TODO)\n\nA function just like `reduce_right`. However, there's a difference:\n\nIn paramorphism, your reducer's arguments are the current value, the reduction of all previous values, and the list of values that formed that reduction.\n\n```python\n# TODO\n```\n\n### Apomorphism (TODO)\n\nit's the opposite of paramorphism, just as anamorphism is the opposite of catamorphism. Whereas with paramorphism, you combine with access to the accumulator and what has been accumulated, apomorphism lets you `unfold` with the potential to return early.\n\n## Setoid (TODO)\n\nAn object that has an `equals` function which can be used to compare other objects of the same type.\n\nMake array a setoid:\n\n```python \n# TODO\n```\n\n## Semigroup (TODO)\n\nAn object that has a `concat` function that combines it with another object of the same type.\n\n```python\n# TODO\n```\n\n## Foldable (TODO)\n\nAn object that has a `reduce` function that applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.\n\n```python\n# TODO\n```\n\n## Lens (TODO)\n\nA lens is a structure (often an object or function) that pairs a getter and a non-mutating setter for some other data\nstructure.\n\n```python\n# TODO\n```\n\nLenses are also composable. This allows easy immutable updates to deeply nested data.\n\n```python\n# TODO\n```\n\n## Type Signatures (TODO)\n\n__Further reading__\n* [Ramda's type signatures](https://github.com/ramda/ramda/wiki/Type-Signatures)\n* [Mostly Adequate Guide](https://drboolean.gitbooks.io/mostly-adequate-guide/content/ch7.html#whats-your-type)\n* [What is Hindley-Milner?](http://stackoverflow.com/a/399392/22425) on Stack Overflow\n\n## Algebraic data type (TODO)\n\nA composite type made from putting other types together. Two common classes of algebraic types are [sum](#sum-type-todo) and [product](#product-type-todo).\n\n### Sum type (TODO)\n\nA Sum type is the combination of two types together into another one. It is called sum because the number of possible values in the result type is the sum of the input types.\n\n```python\n# TODO\n```\n\nSum types are sometimes called union types, discriminated unions, or tagged unions.\n\nThe [sumtypes](https://github.com/radix/sumtypes/) library in Python helps with defining and using union types.\n\n### Product type (TODO)\n\nA __product__ type combines types together in a way you're probably more familiar with:\n\n```python\n# TODO\n```\n\nSee also [Set theory](https://en.wikipedia.org/wiki/Set_theory).\n\n## Option (TODO)\n\nOption is a [sum type](#sum-type-todo) with two cases often called `Some` and `None`.\n\nOption is useful for composing functions that might not return a value.\n\n```python\n# TODO\n```\n\n`Option` is also known as `Maybe`. `Some` is sometimes called `Just`. `None` is sometimes called `Nothing`.\n\n## Function (TODO)\n\nA __function__ `f :: A =\u003e B` is an expression - often called arrow or lambda expression - with __exactly one (immutable)__ parameter of type `A` and __exactly one__ return value of type `B`. That value depends entirely on the argument, making functions context-independent, or [referentially transparent](#referential-transparency-todo). What is implied here is that a function must not produce any hidden [side effects](#side-effects) - a function is always [pure](#purity), by definition. These properties make functions pleasant to work with: they are entirely deterministic and therefore predictable. Functions enable working with code as data, abstracting over behaviour:\n\n```python\n# TODO\n```\n\n## Partial function (TODO)\n\nA partial function is a [function](#function-todo) which is not defined for all arguments - it might return an unexpected result or may never terminate. Partial functions add cognitive overhead, they are harder to reason about and can lead to runtime errors. Some examples:\n\n```python\n# TODO\n```\n\n### Dealing with partial functions (TODO)\n\nPartial functions are dangerous as they need to be treated with great caution. You might get an unexpected (wrong) result or run into runtime errors. Sometimes a partial function might not return at all. Being aware of and treating all these edge cases accordingly can become very tedious.\nFortunately a partial function can be converted to a regular (or total) one. We can provide default values or use guards to deal with inputs for which the (previously) partial function is undefined. Utilizing the [`Option`](#option-todo) type, we can yield either `Some(value)` or `None` where we would otherwise have behaved unexpectedly:\n\n```python\n# TODO\n```\n","funding_links":["https://github.com/sponsors/dry-python","https://opencollective.com/dry-python"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdry-python%2Ffunctional-jargon-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdry-python%2Ffunctional-jargon-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdry-python%2Ffunctional-jargon-python/lists"}