FP::Either - keep two kinds of values in one kind of place
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;
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.
FP::Failure (which only wraps the error case).
Implements: FP::Abstract::Pure, FP::Struct::Show
This is alpha software! Read the status section in the package README or on the website.
To install FunctionalPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FunctionalPerl
CPAN shell
perl -MCPAN -e shell install FunctionalPerl
For more information on module installation, please visit the detailed CPAN module installation guide.