Skip to content

Commit 2230995

Browse files
committed
Version 0.11 release
1 parent dc1c253 commit 2230995

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ incremental in minor, bugfixes only are patches.
66
See (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

docs/pages/functions.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ functions with one argument and one return to be composed.
2323
Only 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+
2639
box
2740
---
2841

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ style = "https://raw.githubusercontent.com/wemake-services/wemake-python-stylegu
99

1010
[tool.poetry]
1111
name = "returns"
12-
version = "0.10.0"
12+
version = "0.11.0"
1313
description = "Make your functions return something meaningful, typed, and safe!"
1414
license = "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"

returns/functions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@
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+
1348
def compose(
1449
first: Callable[[_FirstType], _SecondType],
1550
second: Callable[[_SecondType], _ThirdType],
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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*'

0 commit comments

Comments
 (0)