File: test_maybe_bind.py

package info (click to toggle)
python-returns 0.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: python: 11,000; makefile: 18
file content (25 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from returns.maybe import Maybe, Nothing, Some


def test_bind_some():
    """Ensures that bind works correctly."""

    def factory(inner_value: int) -> Maybe[int]:
        return Some(inner_value * 2)

    input_value = 5
    bound = Some(input_value).bind(factory)

    assert bound == factory(input_value)
    assert str(bound) == '<Some: 10>'


def test_bind_optional():
    """Ensures that bind_optional works correctly."""

    def factory(inner_value: int) -> int | None:
        return inner_value or None

    assert Some(1).bind_optional(factory) == Some(1)
    assert Some(0).bind_optional(factory) == Nothing
    assert Nothing.bind_optional(factory) == Nothing