- https://github.com/cognitect-labs/transducers-python/blob/master/tests/transducer_tests.py
- https://www.infoq.com/articles/saga-orchestration-outbox/
- https://github.com/clojure/clojure/blob/7529bc90a35eba940581311d7dfed21fec22b4f5/src/clj/clojure/core.clj#L6875
- https://github.com/cognitect-labs/transducers-python/blob/11ac3e5c78a5a9dd30719d3aba91bf333c249a94/transducers/transducers.py#L46
- https://medium.com/@olxc/referential-transparency-93352c2dd713
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABCMeta | |
from dataclasses import dataclass | |
from typing import ( | |
Any, | |
ClassVar, | |
Iterable, | |
Protocol, | |
Union, | |
get_args, | |
get_origin, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
func Map[T1, T2 any](s []T1, f func(T1) T2) []T2 { | |
newSlice := make([]T2, 0) | |
for _, item := range s { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from returns.result import Result, Success, Failure | |
def example_function(arg: str) -> Result[int, str]: | |
if arg.isnumeric(): | |
return Success(int(arg)) | |
return Failure('"{0}" is not a number'.format(arg)) | |
def test_if_failure_is_created_at_example_function(returns): | |
with returns.has_trace(Failure, example_function): | |
Success('not a number').bind(example_function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from returns.result import Failure, Result | |
from returns.primitives.tracing import collect_traces | |
@collect_traces | |
def get_failure(argument: str) -> Result[str, str]: | |
return Failure(argument) | |
failure = get_failure('example') | |
for trace_line in failure.trace: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class Example: | |
def __init__(self) -> None: | |
if os.getenv('RETURNS_TRACE'): | |
self._tracking = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from returns.result import Failure, Result, Success | |
def is_even(number: int) -> Result[int, int]: | |
if arg % 2 == 0: | |
return Success(number) | |
return Failure(number) | |
assert is_even(2) == Success(2) | |
assert is_even(1) == Failure(1) |