NAME

FP::Either - keep two kinds of values in one kind of place

SYNOPSIS

use FP::Either;
my $a = Left 1;
my $b = Right 1;
ok is_Left $a;
ok !is_Right $a;
ok is_Right $b;
ok $a->isa("FP::_::Either");
ok $a->isa("FP::Either::Left");
is $a->value, 1;
is $b->value, 1;

use FP::List;
use FP::Equal;
use FP::Either ":all";
my $l = list Left(9), Left(-8), Right(5);
ok equal rights($l), list 5;
ok equal lefts($l), list 9, -8;

DESCRIPTION

These are used to mark (wrap) two different kinds of data for proper distinction in a place that should hold either.

`Right` is typically used for the 'right' way, or successful path, or similar. `Left` would be for the other case, for example to indicate a failure, or whatever suits the situation at hands.

The naming used here (`Either` with `Left` and `Right` members) is the one for the data types that the Haskell language uses for error handling. Rust calls the corresponding types `Result`, with `Err` and `Ok` members. But given that, especially in Perl, there's less use of such a module for error handling, but more for other purposes, the Haskell naming seems like a better match.

SEE ALSO

FP::Failure (which only wraps the error case).

Implements: FP::Abstract::Pure, FP::Struct::Show

NOTE

This is alpha software! Read the status section in the package README or on the website.