GithubHelp home page GithubHelp logo

denisdubochevalier / monad Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 76 KB

Implementation of monads in go with generics

License: MIT License

Go 99.72% Makefile 0.28%
functional-programming monad monads

monad's Introduction

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.

monad's People

Contributors

denisdubochevalier avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.