File tree Expand file tree Collapse file tree 5 files changed +64
-3
lines changed
typesafety/test_functions Expand file tree Collapse file tree 5 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ incremental in minor, bugfixes only are patches.
66See (0Ver)[ https://0ver.org/ ] .
77
88
9- ## 0.11.0 WIP
9+ ## 0.11.0
1010
1111### Features
1212
@@ -17,9 +17,14 @@ See (0Ver)[https://0ver.org/].
1717- ** Breaking** : dropped support of zero argument functions for ` Nothing.fix `
1818- ** Breaking** : dropped support of zero argument functions for ` Nothing.rescue `
1919- ` Maybe ` now has ` .failure() ` to match the same API as ` Result `
20+ - Adds ` identity ` function
2021- Adds ` tap ` function
2122- Now ` pipe ` allows to pipe 8 steps
22- - Adds ` coalesce_conatiner ` coverter
23+ - Adds ` coalesce_result ` and ` coalesce_maybe ` coverters
24+
25+ ### Bugfixes
26+
27+ - Fixes that code inside ` .fix ` and ` .rescue ` of ` Maybe ` might be called twice
2328
2429### Misc
2530
Original file line number Diff line number Diff line change @@ -23,6 +23,19 @@ functions with one argument and one return to be composed.
2323Only works with regular functions (not async).
2424
2525
26+ identity
27+ --------
28+
29+ We also ship :func: `returns.functions.identity ` function
30+ to help you with the composition.
31+
32+ Identity function is a simple concept: it just returns its argument.
33+ If you wonder why do we need this function, please read below:
34+
35+ - `Practical Usage of Identity Function <https://blog.bigbinary.com/2018/03/20/practical-usage-of-identity-function.html >`_ (JS)
36+ - `Using Identity Functions <https://emilvarga.com/posts/2016/08/01/using-identity-functions >`_ (Scala)
37+
38+
2639box
2740---
2841
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ style = "https://raw.githubusercontent.com/wemake-services/wemake-python-stylegu
99
1010[tool .poetry ]
1111name = " returns"
12- version = " 0.10 .0"
12+ version = " 0.11 .0"
1313description = " Make your functions return something meaningful, typed, and safe!"
1414license = " BSD-2-Clause"
1515
@@ -27,6 +27,8 @@ keywords = [
2727 " fp" ,
2828 " monads" ,
2929 " monad" ,
30+ " monad transformers" ,
31+ " composition" ,
3032 " type-safety" ,
3133 " mypy" ,
3234 " railway-oriented-programming"
Original file line number Diff line number Diff line change 1010_ThirdType = TypeVar ('_ThirdType' )
1111
1212
13+ def identity (instance : _FirstType ) -> _FirstType :
14+ """
15+ Function that returns its argument.
16+
17+ .. code:: python
18+
19+ >>> identity(1)
20+ 1
21+ >>> identity([1, 2, 3])
22+ [1, 2, 3]
23+
24+ Why do we even need this?
25+ Identity functions help us with the composition.
26+
27+ Imagine, that you want to use :func:`returns.converters.coalesce_result`
28+ like so:
29+
30+ .. code:: python
31+
32+ from returns.result import Result
33+ from returns.converters import coalesce_result
34+
35+ numbers: Result[int, float]
36+ # Now you want to fold `number` into `int` type:
37+ number: int = coalesce_result(identity, int)(numbers)
38+ # Done!
39+
40+ See also:
41+ - https://en.wikipedia.org/wiki/Identity_function
42+ - https://stackoverflow.com/a/21506571/4842742
43+
44+ """
45+ return instance
46+
47+
1348def compose (
1449 first : Callable [[_FirstType ], _SecondType ],
1550 second : Callable [[_SecondType ], _ThirdType ],
Original file line number Diff line number Diff line change 1+ - case : identity_function
2+ disable_cache : true
3+ main : |
4+ from returns.functions import identity
5+
6+ reveal_type(identity(1)) # N: Revealed type is 'builtins.int*'
You can’t perform that action at this time.
0 commit comments