All Projects → dbrattli → Oslash

dbrattli / Oslash

Licence: mit
Functors, Applicatives, And Monads in Python

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Oslash

operators-service
Service Object based on Either Monad
Stars: ✭ 27 (-95.19%)
Mutual labels:  monads
declarative-form-generator
A simple react form generator using functional programming concepts
Stars: ✭ 14 (-97.5%)
Mutual labels:  monads
True Myth
A library for safer and smarter error- and "nothing"-handling in TypeScript.
Stars: ✭ 360 (-35.83%)
Mutual labels:  monads
Forbind
Functional chaining and promises in Swift
Stars: ✭ 44 (-92.16%)
Mutual labels:  monads
dry-matcher
Flexible, expressive pattern matching for Ruby
Stars: ✭ 91 (-83.78%)
Mutual labels:  monads
monadic-cfa
Generic implementation of different CFA families based on monadic decomposition
Stars: ✭ 16 (-97.15%)
Mutual labels:  monads
futils
Utilities for generic functional programming
Stars: ✭ 21 (-96.26%)
Mutual labels:  monads
Fetch
Simple & Efficient data access for Scala and Scala.js
Stars: ✭ 453 (-19.25%)
Mutual labels:  monads
Narvalo.NET
Applied functional patterns for C#. Money and Currency types. MVP framework. (Obsolete)
Stars: ✭ 16 (-97.15%)
Mutual labels:  monads
Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+606.6%)
Mutual labels:  monads
meiga
🧙 A simple, typed and monad-based Result type for Python.
Stars: ✭ 24 (-95.72%)
Mutual labels:  monads
fpEs
Functional Programming for EcmaScript(Javascript)
Stars: ✭ 40 (-92.87%)
Mutual labels:  monads
Mu Scala
Mu is a purely functional library for building RPC endpoint based services with support for RPC and HTTP/2
Stars: ✭ 266 (-52.58%)
Mutual labels:  monads
freestyle-cassandra
Freestyle Cassandra
Stars: ✭ 17 (-96.97%)
Mutual labels:  monads
Whyhaskellmatters
In this article I try to explain why Haskell keeps being such an important language by presenting some of its most important and distinguishing features and detailing them with working code examples. The presentation aims to be self-contained and does not require any previous knowledge of the language.
Stars: ✭ 418 (-25.49%)
Mutual labels:  monads
monadiccp
Monadic Constraint Programming framework
Stars: ✭ 25 (-95.54%)
Mutual labels:  monads
typescript-monads
📚Write safer TypeScript using Maybe, List, Result, and Either monads.
Stars: ✭ 94 (-83.24%)
Mutual labels:  monads
Learn Fp
learn-by-doing course/tutorial for functional programming on scala
Stars: ✭ 548 (-2.32%)
Mutual labels:  monads
Arrow
Λrrow - Functional companion to Kotlin's Standard Library
Stars: ✭ 4,771 (+750.45%)
Mutual labels:  monads
Monio
Async-capable IO monad for JS
Stars: ✭ 311 (-44.56%)
Mutual labels:  monads

Functors, Applicatives, And Monads in Python

Python package

OSlash (Ø) is a library for playing with functional programming in Python 3.8+. It's an attempt to re-implement some of the code from Learn You a Haskell for Great Good! in Python 3.8. OSlash unifies functional and object oriented paradigms by grouping related functions within classes. Objects are however never used for storing values or mutable data, and data only lives within function closures.

OSlash is intended to be a tutorial. For practical functional programming in Python in production environments you should use Expression instead.

Install

> pip3 install oslash

The project currently contains implementations for:

Abstract Base Classes

  • Functor, for stuff that can be mapped
  • Applicative, for callable stuff
  • Monoid, for associative stuff
  • Monad, for monadic stuff

And Some Monads

  • Identity, boxed stuff in its simplest form
  • Maybe (Just | Nothing), for optional stuff
  • Either (Right | Left), for possible failures
  • List, purely functional list of stuff
  • IO Action, for impure stuff
  • Writer, for logging stuff
  • Reader, for callable stuff
  • State, for stateful computations of stuff
  • Cont, for continuation of stuff

Monadic functions

  • >>, for sequencing monadic actions
  • lift, for mapping a function over monadic values
  • join, for removing one level of monadic structure
  • compose, for composing monadic functions

Utility functions

  • compose, for composing 0 to n functions

But why?

Yes, I know there are other projects out there like PyMonad, fn.py. I'm simply doing this in order to better understand the book. It's so much easier to learn when you implement things yourself. The code may be similar to PyMonad in structure, but is quite different in implementation.

Why is the project called OSlash? OSlash is the Norwegian character called Oslash. Initially I wanted to create a project that used Ø and ø (unicode) for the project name and modules. It didn't work out well, so I renamed it to OSlash.

Examples

Haskell:

> fmap (+3) (Just 2)
Just 5

> (+3) <$> (Just 2)
Just 5

Python:

>>> Just(2).map(lambda x: x+3)
Just 5

>>> (lambda x: x+3) % Just(2)
Just 5

IO Actions:

from oslash import put_line, get_line

main = put_line("What is your name?") | (lambda _:
    get_line() | (lambda name:
    put_line("What is your age?") | (lambda _:
    get_line() | (lambda age:
    put_line("Hello " + name + "!") | (lambda _:
    put_line("You are " + age + " years old"))))))

if __name__ == "__main__":
    main()

Tutorials

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].