Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robrwo/perl-monads
Initial experiments with monads in Perl
https://github.com/robrwo/perl-monads
Last synced: 11 days ago
JSON representation
Initial experiments with monads in Perl
- Host: GitHub
- URL: https://github.com/robrwo/perl-monads
- Owner: robrwo
- Created: 2011-10-09T12:16:28.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2014-03-10T23:09:10.000Z (over 10 years ago)
- Last Synced: 2024-10-11T21:56:34.802Z (about 1 month ago)
- Language: Perl
- Homepage:
- Size: 172 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Monad::Maybe - A quasi-implementation of the Maybe monad in PerlVERSION
Version 0.01SYNOPSIS
use Maybe::Monad;*suc = sub { Just(1 + shift) };
$a = Just(10);
$x->bind(\&suc); # returns Just(11);
*div = lift(sub { $_[0] / $_[1] });
*add = lift(sub { $_[0] + $_[1] });
$b = Just(0);
$c = div($a, $b); # $c is Nothing
$d = add($c, $a); # $d is Nothing
DESCRIPTION
This is an experimental Perl implementation of a class with some
properties of the Maybe monad.Methods
nothing
$x = Monad::Maybe->nothing;A constructor that returns "nothing".
is_nothing
if ($x->is_nothing) { ... }Returns true if the object is "nothing".
just
$x = Monad::Maybe->just( $scalar );A constructor that sets the value of the monad to "just" the
argument.Note that
Monad::Maybe->just( undef )
returns "nothing".
is_just
if ($x->is_just) { ... }Returns true if the object is not "nothing".
bind
$x->bind( $f );Applies a function to the value of `$x', where `$f' is a function
that takes a non-monad as an argument and returns a `Monad::Maybe'
value.If the function does not return a `Monad::Maybe' object, or it
returns an error, then it will return "nothing".If `$x' is nothing, then the `$f' is not actually run, and `bind'
returns "nothing".join
$x->join;Takes a `Monad::Maybe' of a `Monad::Maybe' and returns a
`Monad::Maybe'.If `$x' is not a `Monad::Maybe' of a `Monad::Maybe', then it returns
"nothing".Subroutines
Nothing
$x = Nothing;Shorthand for the nothing constructor.
Just
$x = Just( $v );Shorthand for the just constructor.
lift
$g = lift( $f );Lifts a non-monadic function to a `Monad::Maybe' function.
If any of the values passed to the lifted function are "nothing",
then `$f' is not actually executed, and `$g' returns "nothing".If `$f' dies, then `$g' returns "nothing".
CAVEATS
This is an experimental module. The interface may change completely.SEE ALSO
Data::Monad
https://gist.github.com/peczenyj/9445226AUTHOR
Robert Rothenberg, `'LICENSE AND COPYRIGHT
Copyright 2011-2014 Robert Rothenberg.This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.See http://dev.perl.org/licenses/ for more information.