FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

107 lines
3.1 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.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/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><h1>Fuse</h1><p><strong>FunctionSelect</strong></p>
<p><code>Fuse</code> selects a function that passes a condition.</p>
<h2>Usage</h2><h3>Fuse</h3><pre class="prettyprint source lang-JavaScript"><code>const Fuse = require('@codefeathers/fuse');
const a = 100;
const result = new Fuse(a)
.on(x => x>10,
a => `${a} is greater than 10.`)
.on(x => x&lt;10,
a => `${a} is lesser than 10.`)
.on(x => x===10,
a => `${a} is 10.`)
console.log(result.resolve()); // -> &quot;100 is greater than 10.&quot;</code></pre><h3>FuseIterable</h3><pre class="prettyprint source lang-JavaScript"><code>const { FuseIterable } = require('@codefeathers/fuse');
const temperatures = [ 0, 20, 30 ];
const result = new FuseIterable(temperatures)
.on(temp => temp&lt;10,
() => `Too cold!`)
.on(temp => temp>=10 && temp &lt;25,
() => `Just right.`)
.on(temp => temp>=25,
() => `Too warm!`)
console.log(result.resolve()); // -> [ &quot;Too cold!&quot;, &quot;Just right.&quot;, &quot;Too warm!&quot; ]</code></pre><h2>Docs</h2><p>Docs exist in <code>/docs</code> directory. Will be served soon.</p>
<h2>Development</h2><blockquote>
<p>If you find any mistakes in code/documentation, or if you feel something could be done better, do PR :) I appreciate it.</p>
</blockquote>
<ul>
<li>Always write test spec for any code you add. Make sure they run as intended.</li>
<li>Add/update JSDoc comments as needed.</li>
<li>Use npm scripts for linting, tests, debugging, building docs.</li>
</ul>
<p>Place your test file as <code>testscript.js</code> in root.</p>
<p>The following npm scripts are available: <code>npm run lint</code>, <code>npm test</code>, <code>npm run debug</code>, <code>npm run docs</code>.</p>
<h2>Credits</h2><p><a href="https://github.com/Floofies">@Floofies</a> was of huge help during development of this module.</p>
<p>Also, <a href="https://github.com/trgwii">@TRGWII</a> was a source of inspiration and guidance.</p></article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Fuse.html">Fuse</a></li><li><a href="FuseItem.html">FuseItem</a></li><li><a href="FuseIterable.html">FuseIterable</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 20 2018 02:24:29 GMT+0530 (IST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>