Skip to content

denisdubochevalier/monad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

monad

GitHub go.mod Go version (subdirectory of monorepo) GoDoc Build Status Lint Status Go report Coverage License

Introduction

An expansive Go library that encapsulates a plethora of monadic concepts, rigorously adhering to the three foundational monadic laws. Designed for both pedagogical exploration and industrial-strength functional programming, this package serves as a bedrock for complex, side-effect-free computations.

Note: While the package has matured substantially, it remains a dynamic project. Use cautiously in mission-critical applications.

Features

  • Comprehensive suite of monads including but not limited to Maybe, Either, Result, Identity, List, Reader, Writer, State, and more.
  • Functionally pure methods like FlatMap, Map, and other combinators for side-effect management.
  • Developed with idiomatic Go patterns, optimizing for both readability and performance.
  • Extensive test coverage to ensure adherence to monadic laws.

What's Next

The current version of this monadic library serves as a foundational layer upon which more advanced functionalities can be built. The roadmap ahead is exciting and aims to elevate this project from a basic utility to a comprehensive toolkit for functional programming in Go.

Proper Examples for Each Monad

  • In-Situ Examples: Each monad will be accompanied by in-situ examples to elucidate its practical applications.

  • example_test.go: The examples will be implemented as _test.go files, serving dual roles as instructive code snippets and as integration tests.

New Monads

  • Additional Monads: Expanding the library's repertoire to include other essential monads like the following:
    • RWS (Reader-Writer-State) Monad
    • Promise Monad
    • Try Monad
    • Logic Monad
    • Event Monad
    • Transaction Monad
    • Parser Combinators as Monads
    • Probabilistic Monad
    • Co-Routine Monad
    • Lens Monad
    • Process Monad
  • Community Contributions: We are open to contributions for implementing monads that are currently not part of the library but would offer significant value.

Monad Composition and Monad Transformers

  • Composition: Introducing methods to compose multiple monads into new, more powerful constructs.
  • Transformers: Implementing monad transformers that enable more complex operations by stacking multiple monads.
  • Real-world Scenarios: Accompanying the above with examples and documentation that demonstrate these advanced concepts in action, showing how they solve real-world problems.

Installation

Due to the heavy use of on-the-edge generics, monad requires go version > 1.21.0

go get github.com/denisdubochevalier/monad

Usage

Each monad comes with detailed documentation and example code. Please refer to the GoDoc for individual guides.

import "github.com/denisdubochevalier/monad"

// Example usage with Maybe monad
maybe := monad.Just(42)
result := maybe.FlatMap(func(x int) monad.Maybe {
  return monad.Just(x * 2)
})

Contributing

Contributions are warmly welcomed. Please refer to the CONTRIBUTING.md file for guidelines.

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

About

Implementation of monads in go with generics

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published