Skip to content

trcks.fp.monads.result

Monadic functions for trcks.Result.

Provides utilities for functional composition of synchronous trcks.Result-returning functions.

Examples:

Create and process a value of type trcks.Result:

>>> import math
>>> from trcks.fp.composition import pipe
>>> from trcks.fp.monads import result as r
>>> rslt = pipe(
...     r.construct_success(1_000_000.0),
...     r.tap_success(lambda x: print(f"Processing value {x} ...")),
...     r.map_success_to_result(
...         lambda x: (
...             ("success", math.sqrt(x))
...             if x >= 0
...             else ("failure", "negative value")
...         )
...     ),
...     r.tap_success_to_result(
...         lambda x: (
...             ("success", print(f"Wrote result {x} to disk."))
...             if x < 100
...             else ("failure", "out of disk space")
...         )
...     ),
... )
Processing value 1000000.0 ...
>>> rslt
('failure', 'out of disk space')

If your static type checker cannot infer the type of the arguments passed to trcks.fp.composition.pipe, you can explicitly assign a type:

>>> import math
>>> from trcks import Result, Success
>>> from trcks.fp.composition import Pipeline3, pipe
>>> from trcks.fp.monads import result as r
>>> p: Pipeline3[
...     Success[float],
...     Result[str, float],
...     Result[str, float],
...     Result[str, float],
... ] = (
...     r.construct_success(1_000_000.0),
...     r.tap_success(lambda x: print(f"Processing value {x} ...")),
...     r.map_success_to_result(
...         lambda x: (
...             ("success", math.sqrt(x))
...             if x >= 0
...             else ("failure", "negative value")
...         )
...     ),
...     r.tap_success_to_result(
...         lambda x: (
...             ("success", print(f"Wrote result {x} to disk."))
...             if x < 100
...             else ("failure", "out of disk space")
...         )
...     ),
... )
>>> rslt = pipe(*p)
Processing value 1000000.0 ...
>>> rslt
('failure', 'out of disk space')

construct_failure(value)

Create a trcks.Failure object from a value.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> r.construct_failure(42)
('failure', 42)
Source code in src/trcks/fp/_monads/result.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def construct_failure(value: _F, /) -> Failure[_F]:
    """Create a [trcks.Failure][] object from a value.

    Args:
        value: Value to be wrapped in a [trcks.Failure][] object.

    Returns:
        [trcks.Failure][] object containing the given value.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> r.construct_failure(42)
        ('failure', 42)
    """
    return "failure", value

construct_success(value)

Create a trcks.Success object from a value.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> r.construct_success(42)
('success', 42)
Source code in src/trcks/fp/_monads/result.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def construct_success(value: _S, /) -> Success[_S]:
    """Create a [trcks.Success][] object from a value.

    Args:
        value: Value to be wrapped in a [trcks.Success][] object.

    Returns:
        [trcks.Success][] object containing the given value.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> r.construct_success(42)
        ('success', 42)
    """
    return "success", value

map_failure(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to trcks.Failure values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], _F2]) –

    Function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> add_prefix_to_failure = r.map_failure(lambda s: f"Prefix: {s}")
>>> add_prefix_to_failure(("failure", "negative value"))
('failure', 'Prefix: negative value')
>>> add_prefix_to_failure(("success", 25.0))
('success', 25.0)
Source code in src/trcks/fp/_monads/result.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def map_failure(
    callable_: Callable[Concatenate[_F1, _P], _F2],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F2, _S1]]:
    """Create function that maps [trcks.Failure][] values to [trcks.Failure][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to new [trcks.Failure][] values
            according to the given function and
            leaves [trcks.Success][] values unchanged.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> add_prefix_to_failure = r.map_failure(lambda s: f"Prefix: {s}")
        >>> add_prefix_to_failure(("failure", "negative value"))
        ('failure', 'Prefix: negative value')
        >>> add_prefix_to_failure(("success", 25.0))
        ('success', 25.0)
    """
    return map_failure_to_result(compose(callable_, construct_failure), *args, **kwargs)

map_failure_to_awaitable(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to trcks.AwaitableFailure values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], Awaitable[_F2]]) –

    Asynchronous function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def add_prefix_slowly(s: str) -> str:
...     await asyncio.sleep(0.001)
...     return f"Prefix: {s}"
...
>>> add_prefix_to_failure = r.map_failure_to_awaitable(add_prefix_slowly)
>>> a_rslt_1 = add_prefix_to_failure(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('failure', 'Prefix: not found')
>>> a_rslt_2 = add_prefix_to_failure(("success", 42))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('success', 42)
Source code in src/trcks/fp/monads/result.py
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def map_failure_to_awaitable(
    callable_: Callable[Concatenate[_F1, _P], Awaitable[_F2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F2, _S1]]:
    """Create function that maps [trcks.Failure][] values
    to [trcks.AwaitableFailure][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to [trcks.AwaitableFailure][] values
            according to the given asynchronous function and
            leaves [trcks.Success][] values unchanged.

    Examples:
        >>> import asyncio
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def add_prefix_slowly(s: str) -> str:
        ...     await asyncio.sleep(0.001)
        ...     return f"Prefix: {s}"
        ...
        >>> add_prefix_to_failure = r.map_failure_to_awaitable(add_prefix_slowly)
        >>> a_rslt_1 = add_prefix_to_failure(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('failure', 'Prefix: not found')
        >>> a_rslt_2 = add_prefix_to_failure(("success", 42))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('success', 42)
    """
    return compose(
        ar.construct_from_result,
        ar.map_failure_to_awaitable(callable_, *args, **kwargs),
    )

map_failure_to_awaitable_result(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to trcks.AwaitableResult values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], AwaitableResult[_F2, _S2]]) –

    Asynchronous function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import Result
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def slowly_replace_not_found(s: str) -> Result[str, float]:
...     await asyncio.sleep(0.001)
...     if s == "not found":
...         return "success", 0.0
...     return "failure", s
...
>>> replace_not_found = r.map_failure_to_awaitable_result(
...     slowly_replace_not_found
... )
>>> a_rslt_1 = replace_not_found(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('success', 0.0)
>>> a_rslt_2 = replace_not_found(("failure", "other failure"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('failure', 'other failure')
>>> a_rslt_3 = replace_not_found(("success", 25.0))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
('success', 25.0)
Source code in src/trcks/fp/monads/result.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def map_failure_to_awaitable_result(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResult[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F2, _S1 | _S2]]:
    """Create function that maps [trcks.Failure][] values
    to [trcks.AwaitableResult][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values
            to [trcks.AwaitableFailure][] and [trcks.AwaitableSuccess][] values
            according to the given asynchronous function and
            leaves [trcks.Success][] values unchanged.

    Examples:
        >>> import asyncio
        >>> from trcks import Result
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def slowly_replace_not_found(s: str) -> Result[str, float]:
        ...     await asyncio.sleep(0.001)
        ...     if s == "not found":
        ...         return "success", 0.0
        ...     return "failure", s
        ...
        >>> replace_not_found = r.map_failure_to_awaitable_result(
        ...     slowly_replace_not_found
        ... )
        >>> a_rslt_1 = replace_not_found(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('success', 0.0)
        >>> a_rslt_2 = replace_not_found(("failure", "other failure"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('failure', 'other failure')
        >>> a_rslt_3 = replace_not_found(("success", 25.0))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
        ('success', 25.0)
    """
    return compose(
        ar.construct_from_result,
        ar.map_failure_to_awaitable_result(callable_, *args, **kwargs),
    )

map_failure_to_awaitable_result_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to trcks.AwaitableResultTuple values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], AwaitableResultIterable[_F2, _S2]]) –

    Asynchronous function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import AwaitableResultTuple
>>> from trcks.fp.monads import awaitable_result_tuple as art
>>> from trcks.fp.monads import result as r
>>> async def recover(e: str) -> AwaitableResultTuple[str, float]:
...     await asyncio.sleep(0.001)
...     if e == "not found":
...         return "success", (0.0, 1.0)
...     return "failure", e
...
>>> recover_from_result = r.map_failure_to_awaitable_result_iterable(recover)
>>> a_r_tpl_1 = recover_from_result(("failure", "not found"))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
('success', (0.0, 1.0))
>>> a_r_tpl_2 = recover_from_result(("success", 25.0))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
('success', (25.0,))
Source code in src/trcks/fp/monads/result.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def map_failure_to_awaitable_result_iterable(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResultIterable[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F2, _S1 | _S2]]:
    """Create function that maps [trcks.Failure][] values
    to [trcks.AwaitableResultTuple][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to new [trcks.AwaitableResultTuple][] values
            according to the given asynchronous function and
            leaves [trcks.Success][] values unchanged.

    Examples:
        >>> import asyncio
        >>> from trcks import AwaitableResultTuple
        >>> from trcks.fp.monads import awaitable_result_tuple as art
        >>> from trcks.fp.monads import result as r
        >>> async def recover(e: str) -> AwaitableResultTuple[str, float]:
        ...     await asyncio.sleep(0.001)
        ...     if e == "not found":
        ...         return "success", (0.0, 1.0)
        ...     return "failure", e
        ...
        >>> recover_from_result = r.map_failure_to_awaitable_result_iterable(recover)
        >>> a_r_tpl_1 = recover_from_result(("failure", "not found"))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
        ('success', (0.0, 1.0))
        >>> a_r_tpl_2 = recover_from_result(("success", 25.0))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
        ('success', (25.0,))
    """
    return compose(
        art.construct_from_result,
        art.map_failure_to_awaitable_result_iterable(callable_, *args, **kwargs),
    )

map_failure_to_awaitable_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_failure_to_awaitable_result_iterable.

Source code in src/trcks/fp/monads/result.py
306
307
308
309
310
311
312
313
314
315
316
317
318
@deprecated("Use map_failure_to_awaitable_result_iterable instead")
def map_failure_to_awaitable_result_tuple(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResultTuple[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F2, _S1 | _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.map_failure_to_awaitable_result_iterable][].
    """
    return map_failure_to_awaitable_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

map_failure_to_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to homogeneous tuples.

trcks.Success values are left unchanged.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> def recover(s: str) -> tuple[float, ...]:
...     if s == "not found":
...         return (0.0, 1.0)
...     return ()
...
>>> recover_from_result = r.map_failure_to_iterable(recover)
>>> recover_from_result(("failure", "not found"))
('success', (0.0, 1.0))
>>> recover_from_result(("failure", "other error"))
('success', ())
>>> recover_from_result(("success", 42))
('success', (42,))
Source code in src/trcks/fp/monads/result.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def map_failure_to_iterable(
    callable_: Callable[Concatenate[_F1, _P], Iterable[_S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], SuccessTuple[_S1] | SuccessTuple[_S2]]:
    """Create function that maps [trcks.Failure][] values to homogeneous [tuple][]s.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Failure][] values,
            returning an [collections.abc.Iterable][].
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to homogeneous [tuple][]s wrapped
            in a [trcks.Success][] according to the given function and
            leaves [trcks.Success][] values (wrapped as a tuple) unchanged.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> def recover(s: str) -> tuple[float, ...]:
        ...     if s == "not found":
        ...         return (0.0, 1.0)
        ...     return ()
        ...
        >>> recover_from_result = r.map_failure_to_iterable(recover)
        >>> recover_from_result(("failure", "not found"))
        ('success', (0.0, 1.0))
        >>> recover_from_result(("failure", "other error"))
        ('success', ())
        >>> recover_from_result(("success", 42))
        ('success', (42,))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], SuccessTuple[_S1] | SuccessTuple[_S2]],
    ] = (
        rt.construct_from_result,
        rt.map_failure_to_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

map_failure_to_result(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to trcks.Failure and trcks.Success values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], Result[_F2, _S2]]) –

    Function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> replace_not_found_failure_by_default_value = r.map_failure_to_result(
...     lambda s: ("success", 0.0) if s == "not found" else ("failure", s)
... )
>>> replace_not_found_failure_by_default_value(("failure", "not found"))
('success', 0.0)
>>> replace_not_found_failure_by_default_value(("failure", "other failure"))
('failure', 'other failure')
>>> replace_not_found_failure_by_default_value(("success", 25.0))
('success', 25.0)
Source code in src/trcks/fp/_monads/result.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def map_failure_to_result(
    callable_: Callable[Concatenate[_F1, _P], Result[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F2, _S1 | _S2]]:
    """Create function that maps [trcks.Failure][] values
    to [trcks.Failure][] and [trcks.Success][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to [trcks.Failure][] and [trcks.Success][] values
            according to the given function and
            leaves [trcks.Success][] values unchanged.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> replace_not_found_failure_by_default_value = r.map_failure_to_result(
        ...     lambda s: ("success", 0.0) if s == "not found" else ("failure", s)
        ... )
        >>> replace_not_found_failure_by_default_value(("failure", "not found"))
        ('success', 0.0)
        >>> replace_not_found_failure_by_default_value(("failure", "other failure"))
        ('failure', 'other failure')
        >>> replace_not_found_failure_by_default_value(("success", 25.0))
        ('success', 25.0)
    """

    def mapped_callable(rslt: Result[_F1, _S1]) -> Result[_F2, _S1 | _S2]:
        match rslt:
            case ("failure", value):
                return callable_(value, *args, **kwargs)
            case ("success", _):
                return rslt
            case _:  # pragma: no cover
                assert_type(rslt, Never)  # type: ignore[unreachable]  # pyright: ignore[reportUnreachable]
                msg = f"{type(rslt).__name__!r} is not a valid Result"
                raise TypeError(msg)

    return mapped_callable

map_failure_to_result_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Failure values to new trcks.ResultTuple values.

trcks.Success values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], ResultIterable[_F2, _S2]]) –

    Function to apply to the trcks.Failure values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks import ResultTuple
>>> from trcks.fp.monads import result as r
>>> def expand_error(s: str) -> ResultTuple[str, float]:
...     if s == "not found":
...         return "success", (0.0, 1.0)
...     return "failure", s
...
>>> expand_error_from_result = r.map_failure_to_result_iterable(expand_error)
>>> expand_error_from_result(("failure", "not found"))
('success', (0.0, 1.0))
>>> expand_error_from_result(("failure", "other error"))
('failure', 'other error')
>>> expand_error_from_result(("success", 42))
('success', (42,))
Source code in src/trcks/fp/monads/result.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def map_failure_to_result_iterable(
    callable_: Callable[Concatenate[_F1, _P], ResultIterable[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F2, _S1 | _S2]]:
    """Create function that maps [trcks.Failure][] values
    to new [trcks.ResultTuple][] values.

    [trcks.Success][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Failure][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Maps [trcks.Failure][] values to new [trcks.ResultTuple][] values
            according to the given function and
            leaves [trcks.Success][] values (wrapped as a tuple) unchanged.

    Examples:
        >>> from trcks import ResultTuple
        >>> from trcks.fp.monads import result as r
        >>> def expand_error(s: str) -> ResultTuple[str, float]:
        ...     if s == "not found":
        ...         return "success", (0.0, 1.0)
        ...     return "failure", s
        ...
        >>> expand_error_from_result = r.map_failure_to_result_iterable(expand_error)
        >>> expand_error_from_result(("failure", "not found"))
        ('success', (0.0, 1.0))
        >>> expand_error_from_result(("failure", "other error"))
        ('failure', 'other error')
        >>> expand_error_from_result(("success", 42))
        ('success', (42,))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F2, _S1 | _S2]],
    ] = (
        rt.construct_from_result,
        rt.map_failure_to_result_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

map_failure_to_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_failure_to_result_iterable.

Source code in src/trcks/fp/monads/result.py
418
419
420
421
422
423
424
425
426
427
428
429
430
@deprecated("Use map_failure_to_result_iterable instead")
def map_failure_to_result_tuple(
    callable_: Callable[Concatenate[_F1, _P], ResultTuple[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F2, _S1 | _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.map_failure_to_result_iterable][].
    """
    return map_failure_to_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

map_failure_to_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_failure_to_iterable.

Source code in src/trcks/fp/monads/result.py
433
434
435
436
437
438
439
440
441
@deprecated("Use map_failure_to_iterable instead")
def map_failure_to_tuple(
    callable_: Callable[Concatenate[_F1, _P], tuple[_S2, ...]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], SuccessTuple[_S1] | SuccessTuple[_S2]]:
    """Deprecated alias for [trcks.fp.monads.result.map_failure_to_iterable][]."""
    return map_failure_to_iterable(callable_, *args, **kwargs)  # pragma: no cover

map_success(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to trcks.Success values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], _S2]) –

    Function to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> def increase(n: int) -> int:
...     return n + 1
...
>>> increase_success = r.map_success(increase)
>>> increase_success(("failure", "not found"))
('failure', 'not found')
>>> increase_success(("success", 42))
('success', 43)
Source code in src/trcks/fp/_monads/result.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def map_success(
    callable_: Callable[Concatenate[_S1, _P], _S2],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1, _S2]]:
    """Create function that maps [trcks.Success][] values to [trcks.Success][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values unchanged and
            maps [trcks.Success][] values to new [trcks.Success][] values
            according to the given function.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> def increase(n: int) -> int:
        ...     return n + 1
        ...
        >>> increase_success = r.map_success(increase)
        >>> increase_success(("failure", "not found"))
        ('failure', 'not found')
        >>> increase_success(("success", 42))
        ('success', 43)
    """
    return map_success_to_result(compose(callable_, construct_success), *args, **kwargs)

map_success_to_awaitable(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to trcks.AwaitableSuccess values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], Awaitable[_S2]]) –

    Asynchronous function to apply to the trcks.Success values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def increment_slowly(n: int) -> int:
...     await asyncio.sleep(0.001)
...     return n + 1
...
>>> increase_success = r.map_success_to_awaitable(increment_slowly)
>>> a_rslt_1 = increase_success(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('failure', 'not found')
>>> a_rslt_2 = increase_success(("success", 42))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('success', 43)
Source code in src/trcks/fp/monads/result.py
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
def map_success_to_awaitable(
    callable_: Callable[Concatenate[_S1, _P], Awaitable[_S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1, _S2]]:
    """Create function that maps [trcks.Success][] values
    to [trcks.AwaitableSuccess][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Success][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values unchanged and
            maps [trcks.Success][] values to new [trcks.AwaitableSuccess][] values
            according to the given asynchronous function.

    Examples:
        >>> import asyncio
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def increment_slowly(n: int) -> int:
        ...     await asyncio.sleep(0.001)
        ...     return n + 1
        ...
        >>> increase_success = r.map_success_to_awaitable(increment_slowly)
        >>> a_rslt_1 = increase_success(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('failure', 'not found')
        >>> a_rslt_2 = increase_success(("success", 42))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('success', 43)
    """
    return compose(
        ar.construct_from_result,
        ar.map_success_to_awaitable(callable_, *args, **kwargs),
    )

map_success_to_awaitable_result(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to trcks.AwaitableResult values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], AwaitableResult[_F2, _S2]]) –

    Asynchronous function to apply to the trcks.Success values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> import math
>>> from trcks import Result
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def get_square_root_slowly(x: float) -> Result[str, float]:
...     await asyncio.sleep(0.001)
...     if x < 0:
...         return "failure", "negative value"
...     return "success", math.sqrt(x)
...
>>> get_square_root = r.map_success_to_awaitable_result(get_square_root_slowly)
>>> a_rslt_1 = get_square_root(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('failure', 'not found')
>>> a_rslt_2 = get_square_root(("success", -25.0))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('failure', 'negative value')
>>> a_rslt_3 = get_square_root(("success", 25.0))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
('success', 5.0)
Source code in src/trcks/fp/monads/result.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
def map_success_to_awaitable_result(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResult[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1 | _F2, _S2]]:
    """Create function that maps [trcks.Success][] values
    to [trcks.AwaitableResult][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Success][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values unchanged and
            maps [trcks.Success][] values
            to [trcks.AwaitableFailure][] and [trcks.AwaitableSuccess][] values
            according to the given asynchronous function.

    Examples:
        >>> import asyncio
        >>> import math
        >>> from trcks import Result
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def get_square_root_slowly(x: float) -> Result[str, float]:
        ...     await asyncio.sleep(0.001)
        ...     if x < 0:
        ...         return "failure", "negative value"
        ...     return "success", math.sqrt(x)
        ...
        >>> get_square_root = r.map_success_to_awaitable_result(get_square_root_slowly)
        >>> a_rslt_1 = get_square_root(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('failure', 'not found')
        >>> a_rslt_2 = get_square_root(("success", -25.0))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('failure', 'negative value')
        >>> a_rslt_3 = get_square_root(("success", 25.0))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
        ('success', 5.0)
    """
    return compose(
        ar.construct_from_result,
        ar.map_success_to_awaitable_result(callable_, *args, **kwargs),
    )

map_success_to_awaitable_result_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to trcks.AwaitableResultTuple values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], AwaitableResultIterable[_F2, _S2]]) –

    Asynchronous function to apply to the trcks.Success values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import AwaitableResultTuple
>>> from trcks.fp.monads import awaitable_result_tuple as art
>>> from trcks.fp.monads import result as r
>>> async def slowly_expand(x: float) -> AwaitableResultTuple[str, float]:
...     await asyncio.sleep(0.001)
...     if x < 0:
...         return "failure", "negative"
...     return "success", (x, x * 2)
...
>>> expand_success = r.map_success_to_awaitable_result_iterable(slowly_expand)
>>> a_r_tpl_1 = expand_success(("failure", "not found"))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
('failure', 'not found')
>>> a_r_tpl_2 = expand_success(("success", 5.0))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
('success', (5.0, 10.0))
Source code in src/trcks/fp/monads/result.py
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
def map_success_to_awaitable_result_iterable(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResultIterable[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1 | _F2, _S2]]:
    """Create function that maps [trcks.Success][] values
    to [trcks.AwaitableResultTuple][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Asynchronous function to apply to the [trcks.Success][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values unchanged and
            maps [trcks.Success][] values to new [trcks.AwaitableResultTuple][]
            values according to the given asynchronous function.

    Examples:
        >>> import asyncio
        >>> from trcks import AwaitableResultTuple
        >>> from trcks.fp.monads import awaitable_result_tuple as art
        >>> from trcks.fp.monads import result as r
        >>> async def slowly_expand(x: float) -> AwaitableResultTuple[str, float]:
        ...     await asyncio.sleep(0.001)
        ...     if x < 0:
        ...         return "failure", "negative"
        ...     return "success", (x, x * 2)
        ...
        >>> expand_success = r.map_success_to_awaitable_result_iterable(slowly_expand)
        >>> a_r_tpl_1 = expand_success(("failure", "not found"))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
        ('failure', 'not found')
        >>> a_r_tpl_2 = expand_success(("success", 5.0))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
        ('success', (5.0, 10.0))
    """
    return compose(
        art.construct_from_result,
        art.map_successes_to_awaitable_result_iterable(callable_, *args, **kwargs),
    )

map_success_to_awaitable_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_success_to_awaitable_result_iterable.

Source code in src/trcks/fp/monads/result.py
590
591
592
593
594
595
596
597
598
599
600
601
602
@deprecated("Use map_success_to_awaitable_result_iterable instead")
def map_success_to_awaitable_result_tuple(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResultTuple[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1 | _F2, _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.map_success_to_awaitable_result_iterable][].
    """
    return map_success_to_awaitable_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

map_success_to_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to homogeneous tuples.

trcks.Failure values are left unchanged.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> def duplicate(x: float) -> tuple[float, ...]:
...     return (x, x)
...
>>> duplicate_success = r.map_success_to_iterable(duplicate)
>>> duplicate_success(("failure", "not found"))
('failure', 'not found')
>>> duplicate_success(("success", 5.0))
('success', (5.0, 5.0))
Source code in src/trcks/fp/monads/result.py
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
def map_success_to_iterable(
    callable_: Callable[Concatenate[_S1, _P], Iterable[_S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S2]]:
    """Create function that maps [trcks.Success][] values to homogeneous [tuple][]s.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Success][] values,
            returning an [collections.abc.Iterable][].
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values (wrapped as a tuple) unchanged and
            maps [trcks.Success][] values to homogeneous [tuple][]s
            according to the given function.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> def duplicate(x: float) -> tuple[float, ...]:
        ...     return (x, x)
        ...
        >>> duplicate_success = r.map_success_to_iterable(duplicate)
        >>> duplicate_success(("failure", "not found"))
        ('failure', 'not found')
        >>> duplicate_success(("success", 5.0))
        ('success', (5.0, 5.0))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F1, _S2]],
    ] = (
        rt.construct_from_result,
        rt.map_successes_to_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

map_success_to_result(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to trcks.Failure and trcks.Success values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], Result[_F2, _S2]]) –

    Function to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import math
>>> from trcks import Result
>>> from trcks.fp.monads import result as r
>>> def _get_square_root(x: float) -> Result[str, float]:
...     if x < 0:
...         return "failure", "negative value"
...     return "success", math.sqrt(x)
...
>>> get_square_root = r.map_success_to_result(_get_square_root)
>>> get_square_root(("failure", "not found"))
('failure', 'not found')
>>> get_square_root(("success", -25.0))
('failure', 'negative value')
>>> get_square_root(("success", 25.0))
('success', 5.0)
Source code in src/trcks/fp/_monads/result.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
def map_success_to_result(
    callable_: Callable[Concatenate[_S1, _P], Result[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1 | _F2, _S2]]:
    """Create function that maps [trcks.Success][] values
    to [trcks.Failure][] and [trcks.Success][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values unchanged and
            maps [trcks.Success][] values to [trcks.Failure][] and
            [trcks.Success][] values according to the given function.

    Examples:
        >>> import math
        >>> from trcks import Result
        >>> from trcks.fp.monads import result as r
        >>> def _get_square_root(x: float) -> Result[str, float]:
        ...     if x < 0:
        ...         return "failure", "negative value"
        ...     return "success", math.sqrt(x)
        ...
        >>> get_square_root = r.map_success_to_result(_get_square_root)
        >>> get_square_root(("failure", "not found"))
        ('failure', 'not found')
        >>> get_square_root(("success", -25.0))
        ('failure', 'negative value')
        >>> get_square_root(("success", 25.0))
        ('success', 5.0)
    """

    def mapped_callable(rslt: Result[_F1, _S1]) -> Result[_F1 | _F2, _S2]:
        match rslt:
            case ("failure", _):
                return rslt
            case ("success", value):
                return callable_(value, *args, **kwargs)
            case _:  # pragma: no cover
                assert_type(rslt, Never)  # type: ignore[unreachable]  # pyright: ignore[reportUnreachable]
                msg = f"{type(rslt).__name__!r} is not a valid Result"
                raise TypeError(msg)

    return mapped_callable

map_success_to_result_iterable(callable_, /, *args, **kwargs)

Create function that maps trcks.Success values to new trcks.ResultTuple values.

trcks.Failure values are left unchanged.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], ResultIterable[_F2, _S2]]) –

    Function to apply to the trcks.Success values.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks import ResultTuple
>>> from trcks.fp.monads import result as r
>>> def expand(x: float) -> ResultTuple[str, float]:
...     if x < 0:
...         return "failure", "negative"
...     return "success", (x, x * 2)
...
>>> expand_success = r.map_success_to_result_iterable(expand)
>>> expand_success(("failure", "not found"))
('failure', 'not found')
>>> expand_success(("success", 5.0))
('success', (5.0, 10.0))
>>> expand_success(("success", -5.0))
('failure', 'negative')
Source code in src/trcks/fp/monads/result.py
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
def map_success_to_result_iterable(
    callable_: Callable[Concatenate[_S1, _P], ResultIterable[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1 | _F2, _S2]]:
    """Create function that maps [trcks.Success][] values
    to new [trcks.ResultTuple][] values.

    [trcks.Failure][] values are left unchanged.

    Args:
        callable_: Function to apply to the [trcks.Success][] values.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Leaves [trcks.Failure][] values (wrapped as a tuple) unchanged and
            maps [trcks.Success][] values to new [trcks.ResultTuple][] values
            according to the given function.

    Examples:
        >>> from trcks import ResultTuple
        >>> from trcks.fp.monads import result as r
        >>> def expand(x: float) -> ResultTuple[str, float]:
        ...     if x < 0:
        ...         return "failure", "negative"
        ...     return "success", (x, x * 2)
        ...
        >>> expand_success = r.map_success_to_result_iterable(expand)
        >>> expand_success(("failure", "not found"))
        ('failure', 'not found')
        >>> expand_success(("success", 5.0))
        ('success', (5.0, 10.0))
        >>> expand_success(("success", -5.0))
        ('failure', 'negative')
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F1 | _F2, _S2]],
    ] = (
        rt.construct_from_result,
        rt.map_successes_to_result_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

map_success_to_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_success_to_result_iterable.

Source code in src/trcks/fp/monads/result.py
698
699
700
701
702
703
704
705
706
707
708
709
710
@deprecated("Use map_success_to_result_iterable instead")
def map_success_to_result_tuple(
    callable_: Callable[Concatenate[_S1, _P], ResultTuple[_F2, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1 | _F2, _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.map_success_to_result_iterable][].
    """
    return map_success_to_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

map_success_to_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.map_success_to_iterable.

Source code in src/trcks/fp/monads/result.py
713
714
715
716
717
718
719
720
721
@deprecated("Use map_success_to_iterable instead")
def map_success_to_tuple(
    callable_: Callable[Concatenate[_S1, _P], tuple[_S2, ...]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S2]]:
    """Deprecated alias for [trcks.fp.monads.result.map_success_to_iterable][]."""
    return map_success_to_iterable(callable_, *args, **kwargs)  # pragma: no cover

tap_failure(callable_, /, *args, **kwargs)

Create function that applies a side effect to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], object]) –

    Side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Source code in src/trcks/fp/_monads/result.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def tap_failure(
    callable_: Callable[Concatenate[_F1, _P], object],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1, _S1]]:
    """Create function that applies a side effect to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values and
            returns the original [trcks.Failure][] value.
            Passes on [trcks.Success][] values without side effects.
    """
    return map_failure(i.tap(callable_, *args, **kwargs))

tap_failure_to_awaitable(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], Awaitable[object]]) –

    Asynchronous side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def write_to_disk(output: str) -> None:
...     await asyncio.sleep(0.001)
...     print(f"Wrote '{output}' to disk.")
...
>>> write_failure_to_disk = r.tap_failure_to_awaitable(write_to_disk)
>>> a_rslt_1 = write_failure_to_disk(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
Wrote 'not found' to disk.
('failure', 'not found')
>>> a_rslt_2 = write_failure_to_disk(("success", 42))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('success', 42)
Source code in src/trcks/fp/monads/result.py
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
def tap_failure_to_awaitable(
    callable_: Callable[Concatenate[_F1, _P], Awaitable[object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1, _S1]]:
    """Create function that applies an asynchronous side effect
    to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values and
            returns the original [trcks.Failure][] value.
            Passes on [trcks.Success][] values without side effects.

    Examples:
        >>> import asyncio
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def write_to_disk(output: str) -> None:
        ...     await asyncio.sleep(0.001)
        ...     print(f"Wrote '{output}' to disk.")
        ...
        >>> write_failure_to_disk = r.tap_failure_to_awaitable(write_to_disk)
        >>> a_rslt_1 = write_failure_to_disk(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        Wrote 'not found' to disk.
        ('failure', 'not found')
        >>> a_rslt_2 = write_failure_to_disk(("success", 42))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('success', 42)
    """
    return compose(
        ar.construct_from_result,
        ar.tap_failure_to_awaitable(callable_, *args, **kwargs),
    )

tap_failure_to_awaitable_result(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect with return type trcks.AwaitableResult to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], AwaitableResult[object, _S2]]) –

    Asynchronous side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import Result
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def replace_not_found_with_default(
...     s: str,
... ) -> Result[object, float]:
...     await asyncio.sleep(0.001)
...     if s == "not found":
...         return "success", 0.0
...     return "failure", s
...
>>> recover_from_failure = r.tap_failure_to_awaitable_result(
...     replace_not_found_with_default
... )
>>> a_rslt_1 = recover_from_failure(("failure", "not found"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('success', 0.0)
>>> a_rslt_2 = recover_from_failure(("failure", "other error"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('failure', 'other error')
>>> a_rslt_3 = recover_from_failure(("success", 42))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
('success', 42)
Source code in src/trcks/fp/monads/result.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
def tap_failure_to_awaitable_result(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResult[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1, _S1 | _S2]]:
    """Create function that applies an asynchronous side effect
    with return type [trcks.AwaitableResult][] to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values.
            If the given side effect returns a [trcks.Failure][],
            *the original* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.Success][],
            *this* [trcks.Success][] is returned.
            Passes on [trcks.Success][] values without side effects.

    Examples:
        >>> import asyncio
        >>> from trcks import Result
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def replace_not_found_with_default(
        ...     s: str,
        ... ) -> Result[object, float]:
        ...     await asyncio.sleep(0.001)
        ...     if s == "not found":
        ...         return "success", 0.0
        ...     return "failure", s
        ...
        >>> recover_from_failure = r.tap_failure_to_awaitable_result(
        ...     replace_not_found_with_default
        ... )
        >>> a_rslt_1 = recover_from_failure(("failure", "not found"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('success', 0.0)
        >>> a_rslt_2 = recover_from_failure(("failure", "other error"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('failure', 'other error')
        >>> a_rslt_3 = recover_from_failure(("success", 42))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
        ('success', 42)
    """
    return compose(
        ar.construct_from_result,
        ar.tap_failure_to_awaitable_result(callable_, *args, **kwargs),
    )

tap_failure_to_awaitable_result_iterable(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect with return type trcks.AwaitableResultIterable to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], AwaitableResultIterable[object, _S2]]) –

    Asynchronous side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import AwaitableResultTuple
>>> from trcks.fp.monads import awaitable_result_tuple as art
>>> from trcks.fp.monads import result as r
>>> async def recover(e: str) -> AwaitableResultTuple[object, float]:
...     await asyncio.sleep(0.001)
...     if e == "not found":
...         return "success", (0.0, 1.0)
...     return "failure", e
...
>>> recover_from_failure = r.tap_failure_to_awaitable_result_iterable(recover)
>>> a_r_tpl_1 = recover_from_failure(("failure", "not found"))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
('success', (0.0, 1.0))
>>> a_r_tpl_2 = recover_from_failure(("success", 42))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
('success', (42,))
Source code in src/trcks/fp/monads/result.py
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
def tap_failure_to_awaitable_result_iterable(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResultIterable[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1, _S1 | _S2]]:
    """Create function that applies an asynchronous side effect
    with return type [trcks.AwaitableResultIterable][] to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values.
            If the given side effect returns a [trcks.Failure][],
            *the original* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.SuccessIterable][],
            *this* [trcks.SuccessIterable][] is returned.
            Passes on [trcks.Success][] values (wrapped as a tuple)
            without side effects.

    Examples:
        >>> import asyncio
        >>> from trcks import AwaitableResultTuple
        >>> from trcks.fp.monads import awaitable_result_tuple as art
        >>> from trcks.fp.monads import result as r
        >>> async def recover(e: str) -> AwaitableResultTuple[object, float]:
        ...     await asyncio.sleep(0.001)
        ...     if e == "not found":
        ...         return "success", (0.0, 1.0)
        ...     return "failure", e
        ...
        >>> recover_from_failure = r.tap_failure_to_awaitable_result_iterable(recover)
        >>> a_r_tpl_1 = recover_from_failure(("failure", "not found"))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
        ('success', (0.0, 1.0))
        >>> a_r_tpl_2 = recover_from_failure(("success", 42))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
        ('success', (42,))
    """
    return compose(
        art.construct_from_result,
        art.tap_failure_to_awaitable_result_iterable(callable_, *args, **kwargs),
    )

tap_failure_to_awaitable_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_failure_to_awaitable_result_iterable.

Source code in src/trcks/fp/monads/result.py
880
881
882
883
884
885
886
887
888
889
890
891
892
@deprecated("Use tap_failure_to_awaitable_result_iterable instead")
def tap_failure_to_awaitable_result_tuple(
    callable_: Callable[Concatenate[_F1, _P], AwaitableResultTuple[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1, _S1 | _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.tap_failure_to_awaitable_result_iterable][].
    """
    return tap_failure_to_awaitable_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

tap_failure_to_iterable(callable_, /, *args, **kwargs)

Create function that applies a collections.abc.Iterable-returning side effect to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> def log_err(e: str) -> tuple[None, ...]:
...     print(f"Error logged: {e}")
...     print(f"Alert sent: {e}")
...     return (None, None)
...
>>> log_failure = r.tap_failure_to_iterable(log_err)
>>> log_failure(("failure", "critical"))
Error logged: critical
Alert sent: critical
('success', ('critical', 'critical'))
>>> log_failure(("success", 42))
('success', (42,))
Source code in src/trcks/fp/monads/result.py
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
def tap_failure_to_iterable(
    callable_: Callable[Concatenate[_F1, _P], Iterable[object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], SuccessTuple[_F1] | SuccessTuple[_S1]]:
    """Create function that applies a [collections.abc.Iterable][]-returning
    side effect to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Failure][] value,
            returning an [collections.abc.Iterable][].
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values and converts them
            to [trcks.SuccessTuple][] values containing the original failure
            repeated once per element in the [collections.abc.Iterable][] returned
            by the side effect.
            Passes on [trcks.Success][] values (wrapped as a tuple)
            without side effects.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> def log_err(e: str) -> tuple[None, ...]:
        ...     print(f"Error logged: {e}")
        ...     print(f"Alert sent: {e}")
        ...     return (None, None)
        ...
        >>> log_failure = r.tap_failure_to_iterable(log_err)
        >>> log_failure(("failure", "critical"))
        Error logged: critical
        Alert sent: critical
        ('success', ('critical', 'critical'))
        >>> log_failure(("success", 42))
        ('success', (42,))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], SuccessTuple[_F1] | SuccessTuple[_S1]],
    ] = (
        rt.construct_from_result,
        rt.tap_failure_to_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

tap_failure_to_result(callable_, /, *args, **kwargs)

Create function that applies a side effect with return type trcks.Result to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], Result[object, _S2]]) –

    Side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Source code in src/trcks/fp/_monads/result.py
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def tap_failure_to_result(
    callable_: Callable[Concatenate[_F1, _P], Result[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1, _S1 | _S2]]:
    """Create function that applies a side effect with return type [trcks.Result][]
    to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values.
            If the given side effect returns a [trcks.Failure][],
            *the original* [trcks.Failure][] value is returned.
            If the given side effect returns a [trcks.Success][],
            *this* [trcks.Success][] is returned.
            Passes on [trcks.Success][] values without side effects.
    """

    def bypassed_callable(value: _F1) -> Result[_F1, _S2]:
        match callable_(value, *args, **kwargs):
            case ("failure", _):
                return construct_failure(value)
            case ("success", _) as rslt:
                return rslt
            case _ as rslt:  # pragma: no cover
                assert_type(rslt, Never)  # type: ignore[unreachable]  # pyright: ignore[reportUnreachable]
                msg = f"{type(rslt).__name__!r} is not a valid Result"
                raise TypeError(msg)

    return map_failure_to_result(bypassed_callable)

tap_failure_to_result_iterable(callable_, /, *args, **kwargs)

Create function that applies a side effect with return type trcks.ResultIterable to trcks.Failure values.

trcks.Success values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_F1, _P], ResultIterable[object, _S2]]) –

    Side effect to apply to the trcks.Failure value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks import ResultTuple
>>> from trcks.fp.monads import result as r
>>> def attempt_recover(s: str) -> ResultTuple[None, int]:
...     if s == "retry":
...         return "success", (99,)
...     return "failure", None
...
>>> recover_failure = r.tap_failure_to_result_iterable(attempt_recover)
>>> recover_failure(("failure", "retry"))
('success', (99,))
>>> recover_failure(("failure", "fatal"))
('failure', 'fatal')
>>> recover_failure(("success", 42))
('success', (42,))
Source code in src/trcks/fp/monads/result.py
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
def tap_failure_to_result_iterable(
    callable_: Callable[Concatenate[_F1, _P], ResultIterable[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1 | _S2]]:
    """Create function that applies a side effect with return type
    [trcks.ResultIterable][] to [trcks.Failure][] values.

    [trcks.Success][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Failure][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Applies the given side effect to [trcks.Failure][] values.
            If the given side effect returns a [trcks.Failure][],
            *the original* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.SuccessIterable][],
            *this* [trcks.SuccessIterable][] is returned.
            Passes on [trcks.Success][] values (wrapped as a tuple)
            without side effects.

    Examples:
        >>> from trcks import ResultTuple
        >>> from trcks.fp.monads import result as r
        >>> def attempt_recover(s: str) -> ResultTuple[None, int]:
        ...     if s == "retry":
        ...         return "success", (99,)
        ...     return "failure", None
        ...
        >>> recover_failure = r.tap_failure_to_result_iterable(attempt_recover)
        >>> recover_failure(("failure", "retry"))
        ('success', (99,))
        >>> recover_failure(("failure", "fatal"))
        ('failure', 'fatal')
        >>> recover_failure(("success", 42))
        ('success', (42,))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F1, _S1 | _S2]],
    ] = (
        rt.construct_from_result,
        rt.tap_failure_to_result_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

tap_failure_to_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_failure_to_result_iterable.

Source code in src/trcks/fp/monads/result.py
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
@deprecated("Use tap_failure_to_result_iterable instead")
def tap_failure_to_result_tuple(
    callable_: Callable[Concatenate[_F1, _P], ResultTuple[object, _S2]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1 | _S2]]:
    """Deprecated alias for
    [trcks.fp.monads.result.tap_failure_to_result_iterable][].
    """
    return tap_failure_to_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

tap_failure_to_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_failure_to_iterable.

Source code in src/trcks/fp/monads/result.py
1015
1016
1017
1018
1019
1020
1021
1022
1023
@deprecated("Use tap_failure_to_iterable instead")
def tap_failure_to_tuple(
    callable_: Callable[Concatenate[_F1, _P], tuple[object, ...]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], SuccessTuple[_F1] | SuccessTuple[_S1]]:
    """Deprecated alias for [trcks.fp.monads.result.tap_failure_to_iterable][]."""
    return tap_failure_to_iterable(callable_, *args, **kwargs)  # pragma: no cover

tap_success(callable_, /, *args, **kwargs)

Create function that applies a side effect to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], object]) –

    Side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Source code in src/trcks/fp/_monads/result.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
def tap_success(
    callable_: Callable[Concatenate[_S1, _P], object],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1, _S1]]:
    """Create function that applies a side effect to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values without side effects.
            Applies the given side effect to [trcks.Success][] values and
            returns the original [trcks.Success][] value.
    """
    return map_success(i.tap(callable_, *args, **kwargs))

tap_success_to_awaitable(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], Awaitable[object]]) –

    Asynchronous side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def write_to_disk(s: str) -> None:
...     await asyncio.sleep(0.001)
...     print(f"Wrote '{s}' to disk.")
...
>>> write_success_to_disk = r.tap_success_to_awaitable(write_to_disk)
>>> a_rslt_1 = write_success_to_disk(("failure", "missing text"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('failure', 'missing text')
>>> a_rslt_2 = write_success_to_disk(("success", "Hello, world!"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
Wrote 'Hello, world!' to disk.
('success', 'Hello, world!')
Source code in src/trcks/fp/monads/result.py
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
def tap_success_to_awaitable(
    callable_: Callable[Concatenate[_S1, _P], Awaitable[object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1, _S1]]:
    """Create function that applies an asynchronous side effect
    to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values without side effects.
            Applies the given side effect to [trcks.Success][] values and
            returns the original [trcks.Success][] value.

    Examples:
        >>> import asyncio
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def write_to_disk(s: str) -> None:
        ...     await asyncio.sleep(0.001)
        ...     print(f"Wrote '{s}' to disk.")
        ...
        >>> write_success_to_disk = r.tap_success_to_awaitable(write_to_disk)
        >>> a_rslt_1 = write_success_to_disk(("failure", "missing text"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('failure', 'missing text')
        >>> a_rslt_2 = write_success_to_disk(("success", "Hello, world!"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        Wrote 'Hello, world!' to disk.
        ('success', 'Hello, world!')
    """
    return compose(
        ar.construct_from_result,
        ar.tap_success_to_awaitable(callable_, *args, **kwargs),
    )

tap_success_to_awaitable_result(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect with return type trcks.AwaitableResult to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], AwaitableResult[_F2, object]]) –

    Asynchronous side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import Result
>>> from trcks.fp.monads import awaitable_result as ar
>>> from trcks.fp.monads import result as r
>>> async def write_to_disk(s: str, path: str) -> Result[str, None]:
...     if path != "output.txt":
...         return "failure", "write error"
...     await asyncio.sleep(0.001)
...     print(f"Wrote '{s}' to file {path}.")
...     return "success", None
...
>>> a_rslt_1 = r.tap_success_to_awaitable_result(
...     lambda s: write_to_disk(s, "destination.txt")
... )(("failure", "missing text"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
('failure', 'missing text')
>>> a_rslt_2 = r.tap_success_to_awaitable_result(
...     lambda s: write_to_disk(s, "output.txt")
... )(("failure", "missing text"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
('failure', 'missing text')
>>> a_rslt_3 = r.tap_success_to_awaitable_result(
...     lambda s: write_to_disk(s, "destination.txt")
... )(("success", "Hello, world!"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
('failure', 'write error')
>>> a_rslt_4 = r.tap_success_to_awaitable_result(
...     lambda s: write_to_disk(s, "output.txt")
... )(("success", "Hello, world!"))
>>> asyncio.run(ar.to_coroutine_result(a_rslt_4))
Wrote 'Hello, world!' to file output.txt.
('success', 'Hello, world!')
Source code in src/trcks/fp/monads/result.py
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
def tap_success_to_awaitable_result(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResult[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResult[_F1 | _F2, _S1]]:
    """Create function that applies an asynchronous side effect
    with return type [trcks.AwaitableResult][] to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values without side effects.
            Applies the given side effect to [trcks.Success][] values.
            If the given side effect returns a [trcks.Failure][],
            *this* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.Success][],
            *the original* [trcks.Success][] value is returned.

    Examples:
        >>> import asyncio
        >>> from trcks import Result
        >>> from trcks.fp.monads import awaitable_result as ar
        >>> from trcks.fp.monads import result as r
        >>> async def write_to_disk(s: str, path: str) -> Result[str, None]:
        ...     if path != "output.txt":
        ...         return "failure", "write error"
        ...     await asyncio.sleep(0.001)
        ...     print(f"Wrote '{s}' to file {path}.")
        ...     return "success", None
        ...
        >>> a_rslt_1 = r.tap_success_to_awaitable_result(
        ...     lambda s: write_to_disk(s, "destination.txt")
        ... )(("failure", "missing text"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_1))
        ('failure', 'missing text')
        >>> a_rslt_2 = r.tap_success_to_awaitable_result(
        ...     lambda s: write_to_disk(s, "output.txt")
        ... )(("failure", "missing text"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_2))
        ('failure', 'missing text')
        >>> a_rslt_3 = r.tap_success_to_awaitable_result(
        ...     lambda s: write_to_disk(s, "destination.txt")
        ... )(("success", "Hello, world!"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_3))
        ('failure', 'write error')
        >>> a_rslt_4 = r.tap_success_to_awaitable_result(
        ...     lambda s: write_to_disk(s, "output.txt")
        ... )(("success", "Hello, world!"))
        >>> asyncio.run(ar.to_coroutine_result(a_rslt_4))
        Wrote 'Hello, world!' to file output.txt.
        ('success', 'Hello, world!')
    """
    return compose(
        ar.construct_from_result,
        ar.tap_success_to_awaitable_result(callable_, *args, **kwargs),
    )

tap_success_to_awaitable_result_iterable(callable_, /, *args, **kwargs)

Create function that applies an asynchronous side effect with return type trcks.AwaitableResultIterable to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], AwaitableResultIterable[_F2, object]]) –

    Asynchronous side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> import asyncio
>>> from trcks import AwaitableResultTuple
>>> from trcks.fp.monads import awaitable_result_tuple as art
>>> from trcks.fp.monads import result as r
>>> async def write_twice(s: str) -> AwaitableResultTuple[str, None]:
...     await asyncio.sleep(0.001)
...     print(f"Wrote '{s}' twice.")
...     return "success", (None, None)
...
>>> write_success_twice = r.tap_success_to_awaitable_result_iterable(
...     write_twice
... )
>>> a_r_tpl_1 = write_success_twice(("failure", "missing text"))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
('failure', 'missing text')
>>> a_r_tpl_2 = write_success_twice(("success", "Hello, world!"))
>>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
Wrote 'Hello, world!' twice.
('success', ('Hello, world!', 'Hello, world!'))
Source code in src/trcks/fp/monads/result.py
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
def tap_success_to_awaitable_result_iterable(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResultIterable[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1 | _F2, _S1]]:
    """Create function that applies an asynchronous side effect
    with return type [trcks.AwaitableResultIterable][] to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Asynchronous side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values (wrapped as a tuple) without side effects.
            Applies the given side effect to [trcks.Success][] values.
            If the given side effect returns a [trcks.Failure][],
            *this* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.SuccessIterable][],
            *the original* [trcks.Success][] value is repeated once per element
            in the returned [trcks.SuccessIterable][].

    Examples:
        >>> import asyncio
        >>> from trcks import AwaitableResultTuple
        >>> from trcks.fp.monads import awaitable_result_tuple as art
        >>> from trcks.fp.monads import result as r
        >>> async def write_twice(s: str) -> AwaitableResultTuple[str, None]:
        ...     await asyncio.sleep(0.001)
        ...     print(f"Wrote '{s}' twice.")
        ...     return "success", (None, None)
        ...
        >>> write_success_twice = r.tap_success_to_awaitable_result_iterable(
        ...     write_twice
        ... )
        >>> a_r_tpl_1 = write_success_twice(("failure", "missing text"))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_1))
        ('failure', 'missing text')
        >>> a_r_tpl_2 = write_success_twice(("success", "Hello, world!"))
        >>> asyncio.run(art.to_coroutine_result_tuple(a_r_tpl_2))
        Wrote 'Hello, world!' twice.
        ('success', ('Hello, world!', 'Hello, world!'))
    """
    return compose(
        art.construct_from_result,
        art.tap_successes_to_awaitable_result_iterable(callable_, *args, **kwargs),
    )

tap_success_to_awaitable_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_success_to_awaitable_result_iterable.

Source code in src/trcks/fp/monads/result.py
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
@deprecated("Use tap_success_to_awaitable_result_iterable instead")
def tap_success_to_awaitable_result_tuple(
    callable_: Callable[Concatenate[_S1, _P], AwaitableResultTuple[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], AwaitableResultTuple[_F1 | _F2, _S1]]:
    """Deprecated alias for
    [trcks.fp.monads.result.tap_success_to_awaitable_result_iterable][].
    """
    return tap_success_to_awaitable_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

tap_success_to_iterable(callable_, /, *args, **kwargs)

Create function that applies a collections.abc.Iterable-returning side effect to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

Returns:

Examples:

>>> from trcks.fp.monads import result as r
>>> def log_mult(n: int) -> tuple[None, ...]:
...     print(f"v={n}")
...     print(f"v={n}")
...     return None, None
...
>>> log_success = r.tap_success_to_iterable(log_mult)
>>> log_success(("failure", "error"))
('failure', 'error')
>>> log_success(("success", 7))
v=7
v=7
('success', (7, 7))
Source code in src/trcks/fp/monads/result.py
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
def tap_success_to_iterable(
    callable_: Callable[Concatenate[_S1, _P], Iterable[object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]]:
    """Create function that applies a [collections.abc.Iterable][]-returning
    side effect to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Success][] value,
            returning an [collections.abc.Iterable][].
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values (wrapped as a tuple) without side effects.
            Applies the given side effect to [trcks.Success][] values and
            repeats the original element once per element in the
            [collections.abc.Iterable][] returned by the side effect.

    Examples:
        >>> from trcks.fp.monads import result as r
        >>> def log_mult(n: int) -> tuple[None, ...]:
        ...     print(f"v={n}")
        ...     print(f"v={n}")
        ...     return None, None
        ...
        >>> log_success = r.tap_success_to_iterable(log_mult)
        >>> log_success(("failure", "error"))
        ('failure', 'error')
        >>> log_success(("success", 7))
        v=7
        v=7
        ('success', (7, 7))
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F1, _S1]],
    ] = (
        rt.construct_from_result,
        rt.tap_successes_to_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

tap_success_to_result(callable_, /, *args, **kwargs)

Create function that applies a side effect with return type trcks.Result to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], Result[_F2, object]]) –

    Side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Source code in src/trcks/fp/_monads/result.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
def tap_success_to_result(
    callable_: Callable[Concatenate[_S1, _P], Result[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], Result[_F1 | _F2, _S1]]:
    """Create function that applies a side effect with return type [trcks.Result][]
    to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values without side effects.
            Applies the given side effect to [trcks.Success][] values.
            If the given side effect returns a [trcks.Failure][],
            *this* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.Success][],
            *the original* [trcks.Success][] value is returned.
    """

    def bypassed_callable(value: _S1) -> Result[_F2, _S1]:
        match callable_(value, *args, **kwargs):
            case ("failure", _) as rslt:
                return rslt
            case ("success", _):
                return construct_success(value)
            case _ as rslt:  # pragma: no cover
                assert_type(rslt, Never)  # type: ignore[unreachable]  # pyright: ignore[reportUnreachable]
                msg = f"{type(rslt).__name__!r} is not a valid Result"
                raise TypeError(msg)

    return map_success_to_result(bypassed_callable)

tap_success_to_result_iterable(callable_, /, *args, **kwargs)

Create function that applies a side effect with return type trcks.ResultIterable to trcks.Success values.

trcks.Failure values are passed on without side effects.

Parameters:

  • callable_ (Callable[Concatenate[_S1, _P], ResultIterable[_F2, object]]) –

    Side effect to apply to the trcks.Success value.

  • *args (args, default: () ) –

    Positional arguments to be passed to callable_.

  • **kwargs (kwargs, default: {} ) –

    Keyword arguments to be passed to callable_.

Returns:

Examples:

>>> from trcks import ResultTuple
>>> from trcks.fp.monads import result as r
>>> def audit(n: int) -> ResultTuple[str, None]:
...     if n > 0:
...         return "success", (None, None)
...     return "failure", "negative"
...
>>> audit_success = r.tap_success_to_result_iterable(audit)
>>> audit_success(("failure", "oops"))
('failure', 'oops')
>>> audit_success(("success", 7))
('success', (7, 7))
>>> audit_success(("success", -1))
('failure', 'negative')
Source code in src/trcks/fp/monads/result.py
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
def tap_success_to_result_iterable(
    callable_: Callable[Concatenate[_S1, _P], ResultIterable[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1 | _F2, _S1]]:
    """Create function that applies a side effect with return type
    [trcks.ResultIterable][] to [trcks.Success][] values.

    [trcks.Failure][] values are passed on without side effects.

    Args:
        callable_: Side effect to apply to the [trcks.Success][] value.
        *args:
            Positional arguments to be passed to `callable_`.
        **kwargs:
            Keyword arguments to be passed to `callable_`.

    Returns:
        Passes on [trcks.Failure][] values (wrapped as a tuple) without side effects.
            Applies the given side effect to [trcks.Success][] values.
            If the given side effect returns a [trcks.Failure][],
            *this* [trcks.Failure][] is returned.
            If the given side effect returns a [trcks.SuccessIterable][],
            *the original* [trcks.Success][] value is repeated once per element
            in the returned [trcks.SuccessIterable][].

    Examples:
        >>> from trcks import ResultTuple
        >>> from trcks.fp.monads import result as r
        >>> def audit(n: int) -> ResultTuple[str, None]:
        ...     if n > 0:
        ...         return "success", (None, None)
        ...     return "failure", "negative"
        ...
        >>> audit_success = r.tap_success_to_result_iterable(audit)
        >>> audit_success(("failure", "oops"))
        ('failure', 'oops')
        >>> audit_success(("success", 7))
        ('success', (7, 7))
        >>> audit_success(("success", -1))
        ('failure', 'negative')
    """
    c: tuple[
        Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]],
        Callable[[ResultTuple[_F1, _S1]], ResultTuple[_F1 | _F2, _S1]],
    ] = (
        rt.construct_from_result,
        rt.tap_successes_to_result_iterable(callable_, *args, **kwargs),
    )
    return compose(*c)

tap_success_to_result_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_success_to_result_iterable.

Source code in src/trcks/fp/monads/result.py
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
@deprecated("Use tap_success_to_result_iterable instead")
def tap_success_to_result_tuple(
    callable_: Callable[Concatenate[_S1, _P], ResultTuple[_F2, object]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1 | _F2, _S1]]:
    """Deprecated alias for
    [trcks.fp.monads.result.tap_success_to_result_iterable][].
    """
    return tap_success_to_result_iterable(
        callable_, *args, **kwargs
    )  # pragma: no cover

tap_success_to_tuple(callable_, /, *args, **kwargs)

Deprecated alias for trcks.fp.monads.result.tap_success_to_iterable.

Source code in src/trcks/fp/monads/result.py
1325
1326
1327
1328
1329
1330
1331
1332
1333
@deprecated("Use tap_success_to_iterable instead")
def tap_success_to_tuple(
    callable_: Callable[Concatenate[_S1, _P], tuple[object, ...]],
    /,
    *args: _P.args,
    **kwargs: _P.kwargs,
) -> Callable[[Result[_F1, _S1]], ResultTuple[_F1, _S1]]:
    """Deprecated alias for [trcks.fp.monads.result.tap_success_to_iterable][]."""
    return tap_success_to_iterable(callable_, *args, **kwargs)  # pragma: no cover