lodash-fantasy
Version:
Fantasy Land compatible types built with lodash.
1,330 lines (981 loc) • 63.1 kB
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Lodash Fantasy</title>
<meta name="description" content="Fantasy Land compatible types built with lodash." />
<meta property="og:title" content=""/>
<meta property="og:type" content="website"/>
<meta property="og:image" content=""/>
<meta property="og:url" content=""/>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<script src="scripts/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="styles/jaguar.css">
<script>
var config = {"monospaceLinks":true,"cleverLinks":false,"applicationName":"lodash-fantasy","collapseSymbols":false,"default":{"outputSourceFiles":true},"linenums":true,"meta":{"description":"Fantasy Land compatible types built with lodash.","title":"Lodash Fantasy"},"openGraph":{"type":"website"}};
</script>
</head>
<body>
<div id="wrap" class="clearfix">
<div class="navigation">
<h3 class="applicationName"><a href="index.html">lodash-fantasy</a></h3>
<div class="search">
<input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
</div>
<ul class="list">
<li class="item" data-name="Either">
<span class="title">
<a href="Either.html">Either</a>
</span>
<ul class="members itemMembers">
<span class="subtitle">Members</span>
<li data-name="Either.all"><a href="Either.html#.all">all</a></li>
<li data-name="Either.any"><a href="Either.html#.any">any</a></li>
<li data-name="Either.each"><a href="Either.html#.each">each</a></li>
<li data-name="Either.equals"><a href="Either.html#.equals">equals</a></li>
<li data-name="Either.filter"><a href="Either.html#.filter">filter</a></li>
<li data-name="Either.from"><a href="Either.html#.from">from</a></li>
<li data-name="Either.isEither"><a href="Either.html#.isEither">isEither</a></li>
<li data-name="Either.isLeft"><a href="Either.html#.isLeft">isLeft</a></li>
<li data-name="Either.isRight"><a href="Either.html#.isRight">isRight</a></li>
<li data-name="Either.Left"><a href="Either.html#.Left">Left</a></li>
<li data-name="Either.map"><a href="Either.html#.map">map</a></li>
<li data-name="Either.mapIn"><a href="Either.html#.mapIn">mapIn</a></li>
<li data-name="Either.of"><a href="Either.html#.of">of</a></li>
<li data-name="Either.reduce"><a href="Either.html#.reduce">reduce</a></li>
<li data-name="Either.Right"><a href="Either.html#.Right">Right</a></li>
<li data-name="Either.toMaybe"><a href="Either.html#.toMaybe">toMaybe</a></li>
<li data-name="Either.toPromise"><a href="Either.html#.toPromise">toPromise</a></li>
<li data-name="Either.toValidation"><a href="Either.html#.toValidation">toValidation</a></li>
<li data-name="Either.try"><a href="Either.html#.try">try</a></li>
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Either#ap"><a href="Either.html#ap">ap</a></li>
<li data-name="Either#bimap"><a href="Either.html#bimap">bimap</a></li>
<li data-name="Either#chain"><a href="Either.html#chain">chain</a></li>
<li data-name="Either#equals"><a href="Either.html#equals">equals</a></li>
<li data-name="Either#extend"><a href="Either.html#extend">extend</a></li>
<li data-name="Either#get"><a href="Either.html#get">get</a></li>
<li data-name="Either#ifLeft"><a href="Either.html#ifLeft">ifLeft</a></li>
<li data-name="Either#ifRight"><a href="Either.html#ifRight">ifRight</a></li>
<li data-name="Either#isLeft"><a href="Either.html#isLeft">isLeft</a></li>
<li data-name="Either#isRight"><a href="Either.html#isRight">isRight</a></li>
<li data-name="Either#map"><a href="Either.html#map">map</a></li>
<li data-name="Either#of"><a href="Either.html#of">of</a></li>
<li data-name="Either#orElse"><a href="Either.html#orElse">orElse</a></li>
<li data-name="Either#orElseGet"><a href="Either.html#orElseGet">orElseGet</a></li>
<li data-name="Either#orElseThrow"><a href="Either.html#orElseThrow">orElseThrow</a></li>
<li data-name="Either#toMaybe"><a href="Either.html#toMaybe">toMaybe</a></li>
<li data-name="Either#toPromise"><a href="Either.html#toPromise">toPromise</a></li>
<li data-name="Either#toString"><a href="Either.html#toString">toString</a></li>
<li data-name="Either#toValidation"><a href="Either.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Failure">
<span class="title">
<a href="Failure.html">Failure</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Failure.from"><a href="Failure.html#.from">from</a></li>
<li data-name="Failure#ap"><a href="Failure.html#ap">ap</a></li>
<li data-name="Failure#bimap"><a href="Failure.html#bimap">bimap</a></li>
<li data-name="Failure#chain"><a href="Failure.html#chain">chain</a></li>
<li data-name="Failure#concat"><a href="Failure.html#concat">concat</a></li>
<li data-name="Failure#equals"><a href="Failure.html#equals">equals</a></li>
<li data-name="Failure#extend"><a href="Failure.html#extend">extend</a></li>
<li data-name="Failure#ifFailure"><a href="Failure.html#ifFailure">ifFailure</a></li>
<li data-name="Failure#ifSuccess"><a href="Failure.html#ifSuccess">ifSuccess</a></li>
<li data-name="Failure#isFailure"><a href="Failure.html#isFailure">isFailure</a></li>
<li data-name="Failure#isSuccess"><a href="Failure.html#isSuccess">isSuccess</a></li>
<li data-name="Failure#map"><a href="Failure.html#map">map</a></li>
<li data-name="Failure#of"><a href="Failure.html#of">of</a></li>
<li data-name="Failure#orElse"><a href="Failure.html#orElse">orElse</a></li>
<li data-name="Failure#orElseGet"><a href="Failure.html#orElseGet">orElseGet</a></li>
<li data-name="Failure#orElseThrow"><a href="Failure.html#orElseThrow">orElseThrow</a></li>
<li data-name="Failure#toEither"><a href="Failure.html#toEither">toEither</a></li>
<li data-name="Failure#toMaybe"><a href="Failure.html#toMaybe">toMaybe</a></li>
<li data-name="Failure#toPromise"><a href="Failure.html#toPromise">toPromise</a></li>
<li data-name="Failure#toString"><a href="Failure.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Just">
<span class="title">
<a href="Just.html">Just</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Just.from"><a href="Just.html#.from">from</a></li>
<li data-name="Just#ap"><a href="Just.html#ap">ap</a></li>
<li data-name="Just#chain"><a href="Just.html#chain">chain</a></li>
<li data-name="Just#equals"><a href="Just.html#equals">equals</a></li>
<li data-name="Just#extend"><a href="Just.html#extend">extend</a></li>
<li data-name="Just#get"><a href="Just.html#get">get</a></li>
<li data-name="Just#ifJust"><a href="Just.html#ifJust">ifJust</a></li>
<li data-name="Just#ifNothing"><a href="Just.html#ifNothing">ifNothing</a></li>
<li data-name="Just#isJust"><a href="Just.html#isJust">isJust</a></li>
<li data-name="Just#isNothing"><a href="Just.html#isNothing">isNothing</a></li>
<li data-name="Just#map"><a href="Just.html#map">map</a></li>
<li data-name="Just#of"><a href="Just.html#of">of</a></li>
<li data-name="Just#orElse"><a href="Just.html#orElse">orElse</a></li>
<li data-name="Just#orElseGet"><a href="Just.html#orElseGet">orElseGet</a></li>
<li data-name="Just#orElseThrow"><a href="Just.html#orElseThrow">orElseThrow</a></li>
<li data-name="Just#toEither"><a href="Just.html#toEither">toEither</a></li>
<li data-name="Just#toPromise"><a href="Just.html#toPromise">toPromise</a></li>
<li data-name="Just#toString"><a href="Just.html#toString">toString</a></li>
<li data-name="Just#toValidation"><a href="Just.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Left">
<span class="title">
<a href="Left.html">Left</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Left.from"><a href="Left.html#.from">from</a></li>
<li data-name="Left#ap"><a href="Left.html#ap">ap</a></li>
<li data-name="Left#bimap"><a href="Left.html#bimap">bimap</a></li>
<li data-name="Left#chain"><a href="Left.html#chain">chain</a></li>
<li data-name="Left#equals"><a href="Left.html#equals">equals</a></li>
<li data-name="Left#extend"><a href="Left.html#extend">extend</a></li>
<li data-name="Left#get"><a href="Left.html#get">get</a></li>
<li data-name="Left#ifLeft"><a href="Left.html#ifLeft">ifLeft</a></li>
<li data-name="Left#ifRight"><a href="Left.html#ifRight">ifRight</a></li>
<li data-name="Left#isLeft"><a href="Left.html#isLeft">isLeft</a></li>
<li data-name="Left#isRight"><a href="Left.html#isRight">isRight</a></li>
<li data-name="Left#map"><a href="Left.html#map">map</a></li>
<li data-name="Left#of"><a href="Left.html#of">of</a></li>
<li data-name="Left#orElse"><a href="Left.html#orElse">orElse</a></li>
<li data-name="Left#orElseGet"><a href="Left.html#orElseGet">orElseGet</a></li>
<li data-name="Left#orElseThrow"><a href="Left.html#orElseThrow">orElseThrow</a></li>
<li data-name="Left#toMaybe"><a href="Left.html#toMaybe">toMaybe</a></li>
<li data-name="Left#toPromise"><a href="Left.html#toPromise">toPromise</a></li>
<li data-name="Left#toString"><a href="Left.html#toString">toString</a></li>
<li data-name="Left#toValidation"><a href="Left.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Maybe">
<span class="title">
<a href="Maybe.html">Maybe</a>
</span>
<ul class="members itemMembers">
<span class="subtitle">Members</span>
<li data-name="Maybe.all"><a href="Maybe.html#.all">all</a></li>
<li data-name="Maybe.any"><a href="Maybe.html#.any">any</a></li>
<li data-name="Maybe.each"><a href="Maybe.html#.each">each</a></li>
<li data-name="Maybe.equals"><a href="Maybe.html#.equals">equals</a></li>
<li data-name="Maybe.filter"><a href="Maybe.html#.filter">filter</a></li>
<li data-name="Maybe.from"><a href="Maybe.html#.from">from</a></li>
<li data-name="Maybe.isJust"><a href="Maybe.html#.isJust">isJust</a></li>
<li data-name="Maybe.isMaybe"><a href="Maybe.html#.isMaybe">isMaybe</a></li>
<li data-name="Maybe.isNothing"><a href="Maybe.html#.isNothing">isNothing</a></li>
<li data-name="Maybe.Just"><a href="Maybe.html#.Just">Just</a></li>
<li data-name="Maybe.map"><a href="Maybe.html#.map">map</a></li>
<li data-name="Maybe.mapIn"><a href="Maybe.html#.mapIn">mapIn</a></li>
<li data-name="Maybe.Nothing"><a href="Maybe.html#.Nothing">Nothing</a></li>
<li data-name="Maybe.of"><a href="Maybe.html#.of">of</a></li>
<li data-name="Maybe.ofNullable"><a href="Maybe.html#.ofNullable">ofNullable</a></li>
<li data-name="Maybe.reduce"><a href="Maybe.html#.reduce">reduce</a></li>
<li data-name="Maybe.toEither"><a href="Maybe.html#.toEither">toEither</a></li>
<li data-name="Maybe.toPromise"><a href="Maybe.html#.toPromise">toPromise</a></li>
<li data-name="Maybe.toValidation"><a href="Maybe.html#.toValidation">toValidation</a></li>
<li data-name="Maybe.try"><a href="Maybe.html#.try">try</a></li>
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Maybe#ap"><a href="Maybe.html#ap">ap</a></li>
<li data-name="Maybe#chain"><a href="Maybe.html#chain">chain</a></li>
<li data-name="Maybe#equals"><a href="Maybe.html#equals">equals</a></li>
<li data-name="Maybe#extend"><a href="Maybe.html#extend">extend</a></li>
<li data-name="Maybe#get"><a href="Maybe.html#get">get</a></li>
<li data-name="Maybe#ifJust"><a href="Maybe.html#ifJust">ifJust</a></li>
<li data-name="Maybe#ifNothing"><a href="Maybe.html#ifNothing">ifNothing</a></li>
<li data-name="Maybe#isJust"><a href="Maybe.html#isJust">isJust</a></li>
<li data-name="Maybe#isNothing"><a href="Maybe.html#isNothing">isNothing</a></li>
<li data-name="Maybe#map"><a href="Maybe.html#map">map</a></li>
<li data-name="Maybe#of"><a href="Maybe.html#of">of</a></li>
<li data-name="Maybe#orElse"><a href="Maybe.html#orElse">orElse</a></li>
<li data-name="Maybe#orElseGet"><a href="Maybe.html#orElseGet">orElseGet</a></li>
<li data-name="Maybe#orElseThrow"><a href="Maybe.html#orElseThrow">orElseThrow</a></li>
<li data-name="Maybe#toEither"><a href="Maybe.html#toEither">toEither</a></li>
<li data-name="Maybe#toPromise"><a href="Maybe.html#toPromise">toPromise</a></li>
<li data-name="Maybe#toString"><a href="Maybe.html#toString">toString</a></li>
<li data-name="Maybe#toValidation"><a href="Maybe.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Nothing">
<span class="title">
<a href="Nothing.html">Nothing</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Nothing.from"><a href="Nothing.html#.from">from</a></li>
<li data-name="Nothing#ap"><a href="Nothing.html#ap">ap</a></li>
<li data-name="Nothing#chain"><a href="Nothing.html#chain">chain</a></li>
<li data-name="Nothing#equals"><a href="Nothing.html#equals">equals</a></li>
<li data-name="Nothing#extend"><a href="Nothing.html#extend">extend</a></li>
<li data-name="Nothing#get"><a href="Nothing.html#get">get</a></li>
<li data-name="Nothing#ifJust"><a href="Nothing.html#ifJust">ifJust</a></li>
<li data-name="Nothing#ifNothing"><a href="Nothing.html#ifNothing">ifNothing</a></li>
<li data-name="Nothing#isJust"><a href="Nothing.html#isJust">isJust</a></li>
<li data-name="Nothing#isNothing"><a href="Nothing.html#isNothing">isNothing</a></li>
<li data-name="Nothing#map"><a href="Nothing.html#map">map</a></li>
<li data-name="Nothing#of"><a href="Nothing.html#of">of</a></li>
<li data-name="Nothing#orElse"><a href="Nothing.html#orElse">orElse</a></li>
<li data-name="Nothing#orElseGet"><a href="Nothing.html#orElseGet">orElseGet</a></li>
<li data-name="Nothing#orElseThrow"><a href="Nothing.html#orElseThrow">orElseThrow</a></li>
<li data-name="Nothing#toEither"><a href="Nothing.html#toEither">toEither</a></li>
<li data-name="Nothing#toPromise"><a href="Nothing.html#toPromise">toPromise</a></li>
<li data-name="Nothing#toString"><a href="Nothing.html#toString">toString</a></li>
<li data-name="Nothing#toValidation"><a href="Nothing.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Right">
<span class="title">
<a href="Right.html">Right</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Right.from"><a href="Right.html#.from">from</a></li>
<li data-name="Right#ap"><a href="Right.html#ap">ap</a></li>
<li data-name="Right#bimap"><a href="Right.html#bimap">bimap</a></li>
<li data-name="Right#chain"><a href="Right.html#chain">chain</a></li>
<li data-name="Right#equals"><a href="Right.html#equals">equals</a></li>
<li data-name="Right#extend"><a href="Right.html#extend">extend</a></li>
<li data-name="Right#get"><a href="Right.html#get">get</a></li>
<li data-name="Right#ifLeft"><a href="Right.html#ifLeft">ifLeft</a></li>
<li data-name="Right#ifRight"><a href="Right.html#ifRight">ifRight</a></li>
<li data-name="Right#isLeft"><a href="Right.html#isLeft">isLeft</a></li>
<li data-name="Right#isRight"><a href="Right.html#isRight">isRight</a></li>
<li data-name="Right#map"><a href="Right.html#map">map</a></li>
<li data-name="Right#of"><a href="Right.html#of">of</a></li>
<li data-name="Right#orElse"><a href="Right.html#orElse">orElse</a></li>
<li data-name="Right#orElseGet"><a href="Right.html#orElseGet">orElseGet</a></li>
<li data-name="Right#orElseThrow"><a href="Right.html#orElseThrow">orElseThrow</a></li>
<li data-name="Right#toMaybe"><a href="Right.html#toMaybe">toMaybe</a></li>
<li data-name="Right#toPromise"><a href="Right.html#toPromise">toPromise</a></li>
<li data-name="Right#toString"><a href="Right.html#toString">toString</a></li>
<li data-name="Right#toValidation"><a href="Right.html#toValidation">toValidation</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Success">
<span class="title">
<a href="Success.html">Success</a>
</span>
<ul class="members itemMembers">
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Success.from"><a href="Success.html#.from">from</a></li>
<li data-name="Success#ap"><a href="Success.html#ap">ap</a></li>
<li data-name="Success#bimap"><a href="Success.html#bimap">bimap</a></li>
<li data-name="Success#chain"><a href="Success.html#chain">chain</a></li>
<li data-name="Success#concat"><a href="Success.html#concat">concat</a></li>
<li data-name="Success#equals"><a href="Success.html#equals">equals</a></li>
<li data-name="Success#extend"><a href="Success.html#extend">extend</a></li>
<li data-name="Success#ifFailure"><a href="Success.html#ifFailure">ifFailure</a></li>
<li data-name="Success#ifSuccess"><a href="Success.html#ifSuccess">ifSuccess</a></li>
<li data-name="Success#isFailure"><a href="Success.html#isFailure">isFailure</a></li>
<li data-name="Success#isSuccess"><a href="Success.html#isSuccess">isSuccess</a></li>
<li data-name="Success#map"><a href="Success.html#map">map</a></li>
<li data-name="Success#of"><a href="Success.html#of">of</a></li>
<li data-name="Success#orElse"><a href="Success.html#orElse">orElse</a></li>
<li data-name="Success#orElseGet"><a href="Success.html#orElseGet">orElseGet</a></li>
<li data-name="Success#orElseThrow"><a href="Success.html#orElseThrow">orElseThrow</a></li>
<li data-name="Success#toEither"><a href="Success.html#toEither">toEither</a></li>
<li data-name="Success#toMaybe"><a href="Success.html#toMaybe">toMaybe</a></li>
<li data-name="Success#toPromise"><a href="Success.html#toPromise">toPromise</a></li>
<li data-name="Success#toString"><a href="Success.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
<li class="item" data-name="Validation">
<span class="title">
<a href="Validation.html">Validation</a>
</span>
<ul class="members itemMembers">
<span class="subtitle">Members</span>
<li data-name="Validation.all"><a href="Validation.html#.all">all</a></li>
<li data-name="Validation.any"><a href="Validation.html#.any">any</a></li>
<li data-name="Validation.concat"><a href="Validation.html#.concat">concat</a></li>
<li data-name="Validation.each"><a href="Validation.html#.each">each</a></li>
<li data-name="Validation.empty"><a href="Validation.html#.empty">empty</a></li>
<li data-name="Validation.equals"><a href="Validation.html#.equals">equals</a></li>
<li data-name="Validation.Failure"><a href="Validation.html#.Failure">Failure</a></li>
<li data-name="Validation.filter"><a href="Validation.html#.filter">filter</a></li>
<li data-name="Validation.from"><a href="Validation.html#.from">from</a></li>
<li data-name="Validation.isFailure"><a href="Validation.html#.isFailure">isFailure</a></li>
<li data-name="Validation.isSuccess"><a href="Validation.html#.isSuccess">isSuccess</a></li>
<li data-name="Validation.isValidation"><a href="Validation.html#.isValidation">isValidation</a></li>
<li data-name="Validation.map"><a href="Validation.html#.map">map</a></li>
<li data-name="Validation.mapIn"><a href="Validation.html#.mapIn">mapIn</a></li>
<li data-name="Validation.of"><a href="Validation.html#.of">of</a></li>
<li data-name="Validation.reduce"><a href="Validation.html#.reduce">reduce</a></li>
<li data-name="Validation.Success"><a href="Validation.html#.Success">Success</a></li>
<li data-name="Validation.toEither"><a href="Validation.html#.toEither">toEither</a></li>
<li data-name="Validation.toMaybe"><a href="Validation.html#.toMaybe">toMaybe</a></li>
<li data-name="Validation.toPromise"><a href="Validation.html#.toPromise">toPromise</a></li>
<li data-name="Validation.try"><a href="Validation.html#.try">try</a></li>
</ul>
<ul class="typedefs itemMembers">
</ul>
<ul class="methods itemMembers">
<span class="subtitle">Methods</span>
<li data-name="Validation#ap"><a href="Validation.html#ap">ap</a></li>
<li data-name="Validation#bimap"><a href="Validation.html#bimap">bimap</a></li>
<li data-name="Validation#chain"><a href="Validation.html#chain">chain</a></li>
<li data-name="Validation#concat"><a href="Validation.html#concat">concat</a></li>
<li data-name="Validation#equals"><a href="Validation.html#equals">equals</a></li>
<li data-name="Validation#extend"><a href="Validation.html#extend">extend</a></li>
<li data-name="Validation#ifFailure"><a href="Validation.html#ifFailure">ifFailure</a></li>
<li data-name="Validation#ifSuccess"><a href="Validation.html#ifSuccess">ifSuccess</a></li>
<li data-name="Validation#isFailure"><a href="Validation.html#isFailure">isFailure</a></li>
<li data-name="Validation#isSuccess"><a href="Validation.html#isSuccess">isSuccess</a></li>
<li data-name="Validation#map"><a href="Validation.html#map">map</a></li>
<li data-name="Validation#of"><a href="Validation.html#of">of</a></li>
<li data-name="Validation#orElse"><a href="Validation.html#orElse">orElse</a></li>
<li data-name="Validation#orElseGet"><a href="Validation.html#orElseGet">orElseGet</a></li>
<li data-name="Validation#orElseThrow"><a href="Validation.html#orElseThrow">orElseThrow</a></li>
<li data-name="Validation#toEither"><a href="Validation.html#toEither">toEither</a></li>
<li data-name="Validation#toMaybe"><a href="Validation.html#toMaybe">toMaybe</a></li>
<li data-name="Validation#toPromise"><a href="Validation.html#toPromise">toPromise</a></li>
<li data-name="Validation#toString"><a href="Validation.html#toString">toString</a></li>
</ul>
<ul class="events itemMembers">
</ul>
</li>
</ul>
</div>
<div class="main">
<h1 class="page-title" data-filename="data_Either.js.html">Source: data/Either.js</h1>
<section>
<article>
<pre id="source-code" class="prettyprint source linenums"><code>"use strict";
// Third Party
const include = require("include")(__dirname);
const stream = require("lodash/fp");
// Third Party Aliases
const concat = stream.concat;
const curry = stream.curry;
const each = stream.each;
const filter = stream.filter;
const find = stream.find;
const flow = stream.flow;
const get = stream.get;
const isEqual = stream.isEqual;
const map = stream.map;
const negate = stream.negate;
const reduce = stream.reduce;
// Project
const invokeIn = include("src/invokeIn");
/**
* The {@link Either} type is intended for handling disjointed, but related values such as the result or exceptional
* behavior of some function. It is a disjunction similar to <code>Validation</code>. The key difference of the
* {@link Either} type is the focus on the single error as opposed to aggregating many errors. Much like
* <code>Validation</code>, {@link Either} is right-biased.
* @param {*} value - Value to wrap.
* @return {Either} {@link Either} wrapped <code>value</code>.
* @example <caption>Via <code>new</code></caption>
*
* const v1 = new Right(value);
* const v2 = new Left(otherValue);
*
* @example <caption>Via function</caption>
*
* const v3 = Right.from(value);
* const v4 = Left.from(otherValue);
*
* @example <caption>Via Either function</caption>
*
* const fs = require("fs");
* const Either = require("lodash-fantasy/data/Either");
*
* function readFileSyncSafe(filePath, options) {
* let result = null;
*
* try {
* result = Either.Right.from(fs.readFileSync(filePath, options));
* } catch (error) {
* result = Either.Left.from(error);
* }
*
* return result;
* }
*
* module.exports = getValue;
*/
class Either {
/**
* @static
* @property {Right} Right - Either right.
*/
static get Right() {
return Right;
}
/**
* @static
* @property {Left} Left - Either left.
*/
static get Left() {
return Left;
}
/**
* Returns a {@link Either} that resolves all of the eithers in the collection into a single Either.
* @static
* @member
* @param {Either[]} eithers - Collection of eithers.
* @return {Either} A {@link Either} representing all {@link Right} values or a singular {@link Left}.
* @example
*
* const e1 = fs.readFileSync(filePath1);
* // => Right(contents1)
*
* const e2 = fs.readFileSync(filePath2);
* // => Right(contents2)
*
* const e3 = fs.readFileSync(filePath3);
* // => Left(error3)
*
* const e4 = fs.readFileSync(filePath4);
* // => Left(error4)
*
* Either.all([e1, e2]);
* // => Right([contents1, contents2])
*
* Either.all([e1, e2, e3]);
* // => Left(error3)
*
* Either.all([e1, e2, e3, e4]);
* // => Left(error3)
*/
static all(eithers) {
return find(Either.isLeft, eithers) || Either.of(stream(eithers).map(get("value")).reduce(concat, []));
}
/**
* Returns the first {@link Right} in the collection or finally a {@link Left}.
* @static
* @member
* @param {Either[]} eithers - Collection of eithers.
* @return {Either} First {@link Right} or finally a {@link Left}.
* @example
*
* const e1 = fs.readFileSync(filePath1);
* // => Right(contents1)
*
* const e2 = fs.readFileSync(filePath2);
* // => Right(contents2)
*
* const e3 = fs.readFileSync(filePath3);
* // => Left(error3)
*
* const e4 = fs.readFileSync(filePath4);
* // => Left(error4)
*
* Either.any([e1, e2]);
* // => Right(contents1)
*
* Either.any([e2, e3]);
* // => Right(contents2)
*
* Either.any([e3, e4]);
* // => Left(error3)
*/
static any(either) {
return find(Either.isRight, either) || find(Either.isLeft, either);
}
/**
* Creates a new {@link Either} from a <code>value</code>. If the <code>value</code> is already a {@link Either}
* instance, the <code>value</code> is returned unchanged. Otherwise, a new {@link Right} is made with the
* <code>value</code>.
* @static
* @member
* @param {*} value - Value to wrap in a {@link Either}.
* @return {Either} {@link Either} when is the <code>value</code> already wrapped or {@link Right} wrapped
* <code>value</code>.
*
* Either.from();
* // => Right()
*
* Either.from(true);
* // => Right(true)
*
* Either.from(Right.from(value));
* // => Right(value)
*
* Either.from(Left.from(error));
* // => Left(error)
*/
static from(value) {
return this.isEither(value) ? value : this.of(value);
}
/**
* Determines whether or not the value is a {@link Either}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Either}; <code>false</code> for anything else.
* @example
*
* isEither();
* // => false
*
* isEither(Right.from());
* // => true
*
* isEither(Left.from(error));
* // => true
*/
static isEither(value) {
return value instanceof Either;
}
/**
* Determines whether or not the value is a {@link Left}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Left}; <code>false</code> for {@link Right}.
* @example
*
* isLeft();
* // => false
*
* isLeft(Left.from(error));
* // => true
*
* isLeft(Right.from());
* // => false
*/
static isLeft(value) {
return value instanceof Left;
}
/**
* Determines whether or not the value is a {@link Right}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Right}; <code>false</code> for {@link Left}.
* @example
*
* isRight();
* // => false
*
* isRight(Right.from());
* // => true
*
* isRight(Left.from(error));
* // => false
*/
static isRight(value) {
return value instanceof Right;
}
/**
* Wraps the <code>value</code> in a {@link Right}. No parts of <code>value</code> are checked.
* @static
* @member
* @param {*} value - Value to wrap.
* @return {Right} {@link Right} wrapped <code>value</code>.
* @example
*
* Either.of();
* // => Right()
*
* Either.of(true);
* // => Right(true)
*
* Either.of(Right.from(value));
* // => Right(Right(value))
*
* Either.of(Left.from(error));
* // => Right(Left(error))
*/
static of(value) {
return new Right(value);
}
/**
* Tries to invoke a <code>supplier</code>. The result of the <code>supplier</code> is returned in a {@link Right}.
* If an exception is thrown, the error is returned in a {@link Left}. The <code>function</code> takes no arguments.
* @static
* @member
* @param {Supplier} supplier - Function to invoke.
* @return {Either} {@link Right} wrapped supplier result or {@link Left} wrapped <code>error</code>.
* @example
*
* Either.try(normalFunction);
* // => Right(returnValue)
*
* Either.try(throwableFunction);
* // => Left(error)
*/
static try(method) {
try {
return Right.from(method());
} catch (error) {
return Left.from(error);
}
}
constructor(value) {
this.value = value;
}
/**
* Applies the function contained in the instance of a {@link Right} to the value contained in the provided
* {@link Right}, producing a {@link Right} containing the result. If the instance is a {@link Left}, the result
* is the {@link Left} instance. If the instance is a {@link Right} and the provided {@link Either} is {@link Left},
* the result is the provided {@link Left}.
* @abstract
* @function ap
* @memberof Either
* @instance
* @param {Either} other - Value to apply to the function wrapped in the {@link Right}.
* @return {Either} {@link Right} wrapped applied function or {@link Left}.
* @example <caption>Right#ap</caption>
*
* const findPerson = curryN(3, Person.find); // Person.find(name, birthdate, address)
*
* Right.from(findPerson) // => Right(findPerson)
* .ap(Right.try(getName())) // => Right(name)
* .ap(Right.try(getBirthdate())) // => Right(birthdate)
* .ap(Right.try(getAddress())) // => Right(address)
* .ifRight(console.log); // => Log Person.find() response
*/
/**
* Transforms a {@link Either} by applying the first function to the contained value for a {@link Left} or the
* second function for a {@link Right}. The result of each map is wrapped in the corresponding type.
* @abstract
* @function bimap
* @memberof Either
* @instance
* @param {Function} failureMap - Map to apply to the {@link Left}.
* @param {Function} successMap - Map to apply to the {@link Right}.
* @return {Either} {@link Either} wrapped value mapped with the corresponding mapping function.
* @example
*
* // Using lodash/fp/get
* Either.try(loadFile)
* .bimap(get("message"), parseFile)
* // ... other actions in workflow
*/
/**
* Applies the provided function to the value contained for a {@link Right}. The function should return the value
* wrapped in a {@link Either}. If the instance is a {@link Left}, the function is ignored and then instance is
* returned unchanged.
* @abstract
* @function chain
* @memberof Either
* @instance
* @param {Chain.<Either>} method - The function to invoke with the value.
* @return {Either} {@link Either} wrapped value returned by the provided <code>method</code>.
* @example <caption>Right#chain</caption>
*
* // Using lodash/fp/curry and getOr
* const getConfigOption = curry((path, config) => Either.Right.from(getOr(
* Either.Left.from(`Value not found at "${path}"`),
* path,
* config
* )));
*
* Either.of(config)
* .chain(getConfigOption("path.to.option"))
*/
/**
* Determines whether or not the <code>other</code> is equal in value to the current (<code>this</code>). This is
* <strong>not</strong> a reference check.
* @param {*} other - Other value to check.
* @return {Boolean} <code>true</code> if the two Eithers are equal; <code>false</code> if not equal.
* @example <caption>Reflexivity</caption>
*
* v1.equals(v1) === true;
* // => true
*
* @example <caption>Symmetry</caption>
*
* v1.equals(v2) === v2.equals(v1);
* // => true
*
* @example <caption>Transitivity</caption>
*
* (v1.equals(v2) === v2.equals(v3)) && v1.equals(v3)
* // => true
*/
equals(other) {
return isEqual(this, other);
}
/**
* Extends the Either. This is used for workflow continuation where the context has shifted.
* @abstract
* @function extend
* @memberof Either
* @instance
* @param {Extend.<Either>} - method - The function to invoke with the value.
* @return {Either}
* @example <caption>Workflow continuation</caption>
*
* // Workflow from makeRequest.js
* const makeRequest = requestOptions => requestAsPromise(requestOptions)
* .then(Right.from)
* .catch(Left.from);
*
* // Workflow from savePerson.js
* const savePerson = curry((requestOptions, eitherPerson) => eitherPerson
* .map(Person.from)
* .map(person => set("body", person, requestOptions))
* .map(makeRequest)
* );
*
* // Workflow from processResponse.js
* const processResponse = eitherResponse => eitherResponse
* .ifLeft(console.error)
* .ifRight(console.log);
*
* Either.of(person)
* .extend(savePerson({ method: "POST" }))
* .extend(processResponse);
*/
/**
* Returns the value if the instance is a {@link Right} otherwise the <code>null</code>.
* @function get
* @memberof Either
* @instance
* @return {*}
* @example <caption>Right#get</caption>
*
* Right.from(value).get();
* // => value
*
* @example <caption>Left#get</caption>
*
* Left.from(error).get();
* // => null
*/
/**
* Applies the provided function to the value contain for a {@link Left}. Any return value from the function is
* ignored. If the instance is a {@link Right}, the function is ignored and the instance is returned.
* @abstract
* @function ifLeft
* @memberof Either
* @instance
* @param {Consumer} method - The function to invoke with the value.
* @return {Either} Current instance.
* @example <caption>Right#ifLeft</caption>
*
* Right.from(value).ifLeft(doSomething); // void
* // => Right(value)
*
* @example <caption>Left#ifLeft</caption>
*
* Left.from(error).ifLeft(doSomething); // doSomething(error)
* // => Left(error)
*/
/**
* Applies the provided function to the value contain for a {@link Right}. Any return value from the function is
* ignored. If the instance is a {@link Left}, the function is ignored and the instance is returned.
* @abstract
* @function ifRight
* @memberof Either
* @instance
* @param {Consumer} method - The function to invoke with the value.
* @return {Either} Current instance.
* @example <caption>Right#ifRight</caption>
*
* Right.from(value).ifRight(doSomething); // doSomething(value)
* // => Right(value)
*
* @example <caption>Left#ifRight</caption>
*
* Left.from(error).ifRight(doSomething); // void
* // => Left(error)
*/
/**
* Determines whether or not the instance is a {@link Left}.
* @return {Boolean} <code>true</code> if the instance is a {@link Left}; <code>false</code> is not.
* @example <caption>Right#isLeft</caption>
*
* Right.from(value).isLeft();
* // => false
*
* @example <caption>Left#isLeft</caption>
*
* Left.from(error).isLeft();
* // => true
*/
isLeft() {
return this instanceof Left;
}
/**
* Determines whether or not the instance is a {@link Right}.
* @return {Boolean} <code>true</code> if the instance is a {@link Right}; <code>false</code> is not.
* @example <caption>Right</caption>
*
* Right.from(value).isLeft();
* // => true
*
* @example <caption>Left#isRight</caption>
*
* Left.from(error).isLeft();
* // => false
*/
isRight() {
return this instanceof Right;
}
/**
* Applies the provided function to the value contained for a {@link Right} which is, in turn, wrapped in a
* {@link Right}. If the instance is a {@link Left}, the function is ignored and then instance is returned unchanged.
* @abstract
* @function map
* @memberof Either
* @instance
* @param {Function} method - The function to invoke with the value.
* @return {Either} {@link Either} wrapped value mapped with the provided <code>method</code>.
* @example
*
* // Using lodash/fp/flow and sort
* Right.from([1, 3, 2]).map(flow(sort, join(", ")));
* // => Right("1, 2, 3")
*
* Left.from(error).map(flow(sort, join(", ")));
* // => Left(error)
*/
/**
* @see Either.of
*/
of(value) {
return Either.of(value);
}
/**
* Returns the value if the instance is a {@link Right} otherwise returns the value supplied if the instance is a
* {@link Left}.
* @abstract
* @function orElse
* @memberof Either
* @instance
* @param {Consumer} method - The function to invoke with the value.
* @return {*}
* @example <caption>Right#orElse</caption>
*
* Right.from(value).orElse(otherValue);
* // => value
*
* @example <caption>Left#orElse</caption>
*
* Left.from(error).orElse(otherValue);
* // => otherValue
*/
/**
* Return the value if the instance is a {@link Right} otherwise returns the value from the function provided.
* @abstract
* @function orElseGet
* @memberof Either
* @instance
* @param {Supplier} method - The function supplying the optional value.
* @return {*}
* @example <caption>Right#orElseGet</caption>
*
* Right.from(value).orElseGet(getOtherValue);
* // => value
*
* @example <caption>Left#orElseGet</caption>
*
* Left.from(error).orElse(getOtherValue);
* // => otherValue
*/
/**
* Returns the value if the instance is a {@link Right} otheriwse throws the <code>Error</code> supplied by the
* function provided. The function receives the value of the {@link Left} as its argument.
* @abstract
* @function orElseThrow
* @memberof Either
* @instance
* @param {Function} method - The function to invoke with the value.
* @return {*}
* @throws {Error} returned by the provided function.
* @example <caption>Right#orElseThrow</caption>
*
* Right.from(value).orElseThrow(createException);
* // => value
*
* @example <caption>Left#orElseThrow</caption>
*
* Left.from(error).orElseThrow(createException); // throw createException(error)
*/
/**
* Converts the Either to a {@link Maybe}. {@link Right} becomes {@link Just} and {@link Left} becomes
* {@link Nothing}.
* @abstract
* @function toMaybe
* @memberof Either
* @instance
* @param {Maybe} maybe - Maybe implementation.
* @return {Maybe} {@link Maybe} wrapped <code>value</code>.
* @example <caption>Right#toMaybe</caption>
*
* Right.from(value).toMaybe(Maybe);
* // => Maybe.Just(value);
*
* @example <caption>Left#toMaybe</caption>
*
* Left.from(error).toMaybe(Maybe);
* // => Maybe.Nothing();
*/
/**
* Converts the Either to a <code>Promise</code> using the provided <code>Promise</code> implementation.
* @abstract
* @function toPromise
* @memberof Either
* @instance
* @param {Promise} promise - Promise implementation.
* @return {Promise} <code>Promise</code> wrapped <code>value</code>.
* @example <caption>Right#toPromise</caption>
*
* const Bluebird = require("bluebird");
*
* Right.from(value).toPromise(Bluebird);
* // => Promise.resolve(value);
*
* @example <caption>Left#toPromise<