dbrattli / dbrattli/OSlash

How to convert a plain function into a function that returns a monad with inflix operators

Open
#10 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
756
Forks
51
PR merge metrics
No merged PRs in 30d

Description

An example is worth 1000 words:

```python
import oslash

def operation_that_succeeds(input):
return oslash.Right(input + 1)

def operation_that_fails(input):
return oslash.Left("Failure")

def lift(m):
def w(f):
return lambda x: m.unit(f(x))
return w

@lift(oslash.Right)
def pure_function(input):
return input + 1

if __name__ == "__main__":
print(operation_that_succeeds(45) | operation_that_succeeds | pure_function | operation_that_succeeds)
```

How can I rewrite this without needing to implement the `lift` decorator?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.