lodash-fantasy
Version:
Fantasy Land compatible types built with lodash.
1,278 lines (935 loc) • 69.5 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_Validation.js.html">Source: data/Validation.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 isUndefined = stream.isUndefined;
const map = stream.map;
const negate = stream.negate;
const reduce = stream.reduce;
// Project
const invokeIn = include("src/invokeIn");
const invokeWith = include("src/invokeWith");
/**
* The {@link Validation} type is intended for validating values and aggregating failures. It is a disjunction
* similar to <code>Either</code>. The key difference of the {@link Validation} type is the focus on failure
* aggregation as opposed to failing once and ignoring all other failures. Much like <code>Either</code>,
* {@link Validation} is right-biased.
* @param {*} value - Value to wrap.
* @return {Validation} {@link Validation} wrapped <code>value</code>.
* @example <caption>Via <code>new</code></caption>
*
* const v1 = new Success(value);
* const v2 = new Failure(message);
*
* @example <caption>Via function</caption>
*
* const v3 = Success.from(value);
* const v4 = Failure.from(message);
*
* @example <caption>Via validation function</caption>
*
* const isEmpty = require("lodash/fp/isEmpty");
* const isString = require("lodash/fp/isString");
* const Validation = require("lodash-fantasy/data/Validation");
*
* function validateStringPresence(value) {
* return isString(value) && !isEmpty(value) ?
* Validation.Success.from(value) :
* Validation.Failure.from("value should be a non-empty string");
* }
*
* module.exports = validateStringPresence;
*
* @example <caption>Via abstract validation rule</caption>
*
* const Validation = require("lodash-fantasy/data/Validation");
*
* module.exports = (condition, value, message) => condition(value) ?
* Validation.Success.from(value) :
* Validation.Failure.from(message(value)); // Pass value into the message for possible reference
*/
class Validation {
/**
* @static
* @property {Failure} Failure - Validation failure.
*/
static get Failure() {
return Failure;
}
/**
* @static
* @property {Success} Success - Validation success.
*/
static get Success() {
return Success;
}
/**
* Returns a {@link Validation} that resolves all of the validations in the collection into a single validation.
* Unlike <code>Promise</code>, {@link Validation.all} aggregates all of the failures into a single instance of
* {@link Validation}. However, like <code>Promise</code>, {@link Validation.all} collects all of the values
* for successes when <em>all</em> items in the collection are a {@link Success}.
* @static
* @member
* @param {Validation[]} validations - Collection of validations.
* @return {Validation} A {@link Validation} representing all {@link Success} or {@link Failure}
* values.
* @example
*
* const v1 = validationPropertyAIn(context1);
* // => Success(context1)
*
* const v2 = validationPropertyBIn(context2);
* // => Success(context2)
*
* const v3 = validationPropertyCIn(context3);
* // => Failure("A failure.")
*
* const v4 = validationPropertyDIn(context4);
* // => Failure("B failure.")
*
* Validation.all([v1, v2]);
* // => Success([context1, context2])
*
* Validation.all([v1, v2, v3]);
* // => Failure(["A failure"])
*
* Validation.all([v1, v2, v3, v4]);
* // => Failure(["A failure", "B failure"])
*/
static all(validations) {
return find(Validation.isFailure, validations) ?
reduce(Validation.concat, Success.empty(), validations) :
Success.of(stream(validations).map(get("value")).reduce(concat, []));
}
/**
* Returns the first {@link Success} in the collection or a single {@link Failure} for all failures.
* @static
* @member
* @param {Validation[]} validations - Collection of validations.
* @return {Validation} First {@link Success} or reduced {@link Failure}s.
* @example
*
* const v1 = validationPropertyAIn(context1);
* // => Success(context1)
*
* const v2 = validationPropertyBIn(context2);
* // => Success(context2)
*
* const v3 = validationPropertyCIn(context3);
* // => Failure("A failure.")
*
* const v4 = validationPropertyDIn(context4);
* // => Failure("B failure.")
*
* Validation.any([v1, v2]);
* // => Success(context1)
*
* Validation.any([v1, v2, v3]);
* // => Failure(["A failure"])
*
* Validation.any([v1, v2, v3, v4]);
* // => Failure(["A failure", "B failure"])
*/
static any(validations) {
return find(Validation.isSuccess, validations) ||
reduce(Validation.concat, Success.empty(), validations);
}
/**
* Creates an empty {@link Success}.
* @static
* @member
* @return {Success} Empty {@link Success} instance.
* @example
*
* const v1 = Validation.empty();
* // => Success()
*/
static empty() {
return new Success();
}
/**
* Creates a new {@link Validation} from a <code>value</code>. If the <code>value</code> is already a
* {@link Validation} instance, the <code>value</code> is returned unchanged. Otherwise, a new {@link Success} is
* created with the <code>value</code>.
* @static
* @member
* @param {*} value - Value to wrap in a {@link Validation}.
* @return {Validation} {@link Validation} when is the <code>value</code> already wrapped or
* {@link Success} wrapped <code>value</code>.
*
* Validation.from();
* // => Success()
*
* Validation.from(true);
* // => Success(true)
*
* Validation.from(Success.from(value));
* // => Success(value)
*
* Validation.from(Failure.from("Error message"));
* // => Failure(["Error message"])
*/
static from(value) {
return this.isValidation(value) ? value : this.of(value);
}
/**
* Determines whether or not the value is a {@link Failure}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Failure}; <code>false</code> for {@link Success}.
* @example
*
* isFailure();
* // => false
*
* isFailure(null);
* // => false
*
* isFailure(Success.from(0));
* // => false
*
* isFailure(Failure.from("Error"));
* // => true
*/
static isFailure(value) {
return value instanceof Failure;
}
/**
* Determines whether or not the value is a {@link Success}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Success}; <code>false</code> for {@link Failure}.
* @example
*
* isSuccess();
* // => false
*
* isSuccess(null);
* // => false
*
* isSuccess(Success.from(0));
* // => true
*
* isSuccess(Failure.from("Error"));
* // => false
*/
static isSuccess(value) {
return value instanceof Success;
}
/**
* Determines whether or not the value is a {@link Validation}.
* @static
* @member
* @param {*} value - Value to check.
* @return {Boolean} <code>true</code> for {@link Validation}; <code>false</code> for anything else.
* @example
*
* isValidation();
* // => false
*
* isValidation(null);
* // => false
*
* isValidation(Success.from(0));
* // => true
*
* isValidation(Failure.from("Error"));
* // => true
*/
static isValidation(value) {
return value instanceof Validation;
}
/**
* Wraps the <code>value</code> in a {@link Success}. No parts of <code>value</code> are checked.
* @static
* @member
* @param {*} value - Value to wrap.
* @return {Success} {@link Success} wrapped <code>value</code>.
* @example
*
* Validation.of();
* // => Success()
*
* Validation.of(true);
* // => Success(true)
*
* Validation.of(Success.from(value));
* // => Success(Success(value))
*
* Validation.of(Failure.from("Error message"));
* // => Success(Failure(["Error message"]))
*/
static of(value) {
return new Success(value);
}
/**
* Tries to invoke a <code>supplier</code>. The result of the <code>supplier</code> is returned in a {@link Success}.
* If an exception is thrown, the error is returned in a {@link Failure}. The <code>function</code> takes no
* arguments.
* @static
* @member
* @param {Supplier} supplier - Function to invoke.
* @return {Validation} {@link Success} wrapped supplier result or {@link Failure} wrapped <code>error</code>.
* @example
*
* Validation.try(normalFunction);
* // => Success(returnValue)
*
* Validation.try(throwableFunction);
* // => Failure([error])
*/
static try(method) {
try {
return Success.from(method());
} catch (error) {
return Failure.from(error);
}
}
constructor(value) {
this.value = value;
}
/**
* Applies the function contained in the instance of a {@link Success} to the value contained in the provided
* {@link Success}, producing a {@link Success} containing the result. If the instance is a {@link Failure}, the
* result is the {@link Failure} instance. If the instance is a {@link Success} and the provided validation is
* {@link Failure}, the result is the provided {@link Failure}.
* @abstract
* @function ap
* @memberof Validation
* @instance
* @param {Validation} other - Value to apply to the function wrapped in the {@link Success}.
* @return {Validation} {@link Success} wrapped applied function or {@link Failure}.
* @example <caption>Success#ap</caption>
*
* const createPerson = curryN(4, Person.create); // Person.create(name, birthdate, address, email)
*
* Success.from(createPerson) // => Success(createPerson)
* .ap(validate(name)) // => Success(name)
* .ap(validate(birthdate)) // => Success(birthdate)
* .ap(validate(address)) // => Success(address)
* .ap(validate(email)) // => Success(email)
* .ifSuccess(console.log) // => Log Person.create() response
* .orElse(each(console.error)) // => Logs first error since #ap short circuits after the first Failure
*/
/**
* Transforms a {@link Validation} by applying the first function to the contained value for a {@link Failure} or the
* second function for a {@link Success}. The result of each map is wrapped in the corresponding type.
* @abstract
* @function bimap
* @memberof Validation
* @instance
* @param {Function} failureMap - Map to apply to the {@link Failure}.
* @param {Function} successMap - Map to apply to the {@link Success}.
* @return {Validation} {@link Validation} wrapped value mapped with the corresponding mapping function.
* @example
*
* validateRequest(request)
* .bimap(toBadRequestResponse, PersonModel.create)
* // ... other actions in workflow
*/
/**
* Applies the provided function to the value contained for a {@link Success}. The function should return the value
* wrapped in a {@link Validation}. If the instance is a {@link Failure}, the function is ignored and then instance is
* returned unchanged.
* @abstract
* @function chain
* @memberof Validation
* @instance
* @param {Chain.<Validation>} method - The function to invoke with the value.
* @return {Validation} {@link Validation} wrapped value returned by the provided <code>method</code>.
* @example <caption>Success#chain</caption>
*
* const person = { ... };
* const validateResponse = response => HttpStatus.isSuccess(response.statusCode) ?
* Success(response) :
* Failure(response.statusMessage);
*
* const createPerson = flow(Person.create, validateResponse); // Expects instance of Person
*
* const validations = [
* validatePersonName(person), // => Success(person)
* validatePersonBirthdate(person), // => Success(person)
* validatePersonAddress(person), // => Failure([error1])
* validatePersonEmail(person) // => Failure([error2])
* ];
*
* Validation.reduce(Validation.concat, Success.empty(), validations) // => Validation<Person>
* .chain(createPerson) // => Validation<Response>
* .ifSuccess(doSomethingWithResponse)
* .orElse(each(console.error)); // Log all errors
*/
/**
* Concatenates another {@link Validation} instance with the current instance.
* @abstract
* @function concat
* @memberof Validation
* @instance
* @param {Validation} other - Other {@link Validation} to concatenation.
* @return {Validation} Concatenated validations.
* @example <caption>Empty Success with Empty Success</caption>
*
* Success.empty().concat(Success.empty());
* // => Success.empty()
*
* @example <caption>Empty Success with Success</caption>
*
* Success.empty().concat(Success.from(value));
* // => Success(value)
*
* @example <caption>Success with Empty Success</caption>
*
* Success.from(value).concat(Success.empty());
* // => Success(value)
*
* @example <caption>Success1 with Success2</caption>
*
* Success.from(value1).concat(Success.from(value2));
* // => Success(value1)
*
* @example <caption>Any Success with Failure</caption>
*
* anySuccess.concat(Failure.from(error));
* // => Failure([error])
*
* @example <caption>Empty Failure with Any Success</caption>
*
* Failure.from().concat(anySuccess);
* // => Failure([])
*
* @example <caption>Failure with Any Success</caption>
*
* Failure.from(error).concat(Success);
* // => Failure([error])
*
* @example <caption>Empty Failure with Empty Failure</caption>
*
* Failure.from().concat(Failure.from());
* // => Failure([])
*
* @example <caption>Empty Failure with Failure</caption>
*
* Failure.from().concat(Failure.from(error));
* // => Failure([error])
*
* @example <caption>Failure with Failure</caption>
*
* Failure.from(error1).concat(Failure.from(error2));
* // => Failure([error1, error2])
*/
/**
* 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 validations 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 validation. This is used for workflow continuation where the context has shifted.
* @abstract
* @function extend
* @memberof Validation
* @instance
* @param {Extend.<Validation>} - method - The function to invoke with the value.
* @return {Validation}
* @example <caption>Workflow continuation</caption>
*
* // Workflow from makeRequest.js
* const makeRequest = requestOptions => requestAsPromise(requestOptions)
* .then(Success.from)
* .catch(Failure.from);
*
* // Workflow from savePerson.js
* const savePerson = curry((requestOptions, validatedPerson) => {
* return validatedPerson
* .map(Person.from)
* .map(person => set("body", person, requestOptions))
* .map(makeRequest);
* });
*
* // Workflow from processResponse.js
* const processResponse = validatedResponse => validatedResponse
* .ifFailure(console.error)
* .ifSuccess(console.log);
*
* validatePerson(person)
* .extend(savePerson({ method: "POST" }))
* .extend(processResponse);
*/
/**
* Applies the provided function to the value contain for a {@link Failure}. Any return value from the function is
* ignored. If the instance is a {@link Success}, the function is ignored and the instance is returned.
* @abstract
* @function ifFailure
* @memberof Validation
* @instance
* @param {Consumer} method - The function to invoke with the value.
* @return {Validation} Current instance.
* @example <caption>Success#ifFailure</caption>
*
* Success.from(value).ifFailure(doSomething); // void
* // => Success(value)
*
* @example <caption>Failure#ifFailure</caption>
*
* Failure.from(error).ifFailure(doSomething); // doSomething([error])
* // => Failure([error])
*/
/**
* Applies the provided function to the value contain for a {@link Success}. Any return value from the function is
* ignored. If the instance is a {@link Failure}, the function is ignored and the instance is returned.
* @abstract
* @function ifSuccess
* @memberof Validation
* @instance
* @param {Consumer} method - The function to invoke with the value.
* @return {Validation} Current instance.
* @example <caption>Success#ifSuccess</caption>
*
* Success.from(value).ifSuccess(doSomething); // doSomething(value)
* // => Success(value)
*
* @example <caption>Failure#ifSuccess</caption>
*
* Failure.from(error).ifSuccess(doSomething); // void
* // => Failure([error])
*/
/**
* Determines whether or not the instance is a {@link Failure}.
* @return {Boolean} <code>true</code> if the instance is a {@link Failure}; <code>false</code> is not.
* @example <caption>Success#isFailure</caption>
*
* Success.from(value).isFailure();
* // => false
*
* @example <caption>Failure#isFailure</caption>
*
* Failure.from(error).isFailure();
* // => true
*/