Operators and Generics for Monads

Compose generic monadic function pipelines with %>>% and %>-% based on implementing the 'S7' generics fmap() and bind(). Methods are provided for the built-in list type and the maybe class from the 'maybe' package. The concepts are modelled directly after the Monad typeclass in Haskell, but adapted for idiomatic use in R.


monad

Lifecycle: experimental R-CMD-check

The monad package provides generics and generic operators for monadic classes. These are:

  • fmap(), bind() and join() S7 generic functions.
  • %>>% and %>-% pipe operators for fmap() and bind() respectively.

Implementations of the generics are provided for:

  • The list built-in type via purrr. See ?List.
  • The maybe S3 class from maybe. See ?Maybe.

Implementing classes must provide fmap() and either bind() or join(). Method implementations must satisfy the ?"functor-laws" and ?"monad-laws".

The concepts are modelled directly after the Monad typeclass in the functional programming language Haskell. Operator names and calling conventions have been adapted to fit R.

Installation

Install the current release from CRAN:

install.packages("monad")

Or the development version from GitHub:

# install.packages("pak")
pak::pak("mikmart/monad")

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("monad")

0.1.1 by Mikko Marttila, 2 years ago


https://github.com/mikmart/monad, https://mikmart.github.io/monad/


Report a bug at https://github.com/mikmart/monad/issues


Browse source code at https://github.com/cran/monad


Authors: Mikko Marttila [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports S7

Suggests maybe, purrr, roxygen2, testthat


See at CRAN