With fi you can ignore the language constructs and write all your conditional logic in a functional way.
var fi = ;var myVar =;// myVar is "Wargulf"
The library is distributed as an npm module:
npm install fi
If you want to use this in the browser you can use Browserify for all your npm needs.
I also plan to make a client side ready version, hit me up with a github issue if you're interested in seeing that happen sooner.
Basic if statement
var myVar = ; // we need to add .ret() to get the value of a statement// myVar is "flower puppy"
We can make it more interesting and add an else statement:
var myVar = ;// myVar is "space pedals"
Even more interesting using an if-else statement as well:
var myVar = ;// myVar is "human skin"
With a half completed if statment, we can also start chaining more stuff to it later
var myif = ;// do some other stuff, and add to the chain:var myVar = myif;// myVar is "crapware"
Wait, this is not functional enough!
Ok, how about: any value passed into any fi conditional can be either a function, or a value
var myVar =;// myVar is 191
Functions that don't meet a conditional are never executed, and conditionals that dont' meet a condition (like an else if conditional in an if statement evaluated as true) will also never get executed.
var ternary = ternary;var myVar = ;// myVar is 42
Switch statement using an object:
var sw = sw;var myVar =;// myVar is "Some color"
Switch statement using an array (so you can use functions as your keys):
var myVar =;// myVar is "Some color"
This library is pretty fresh and any pull requests or feature requests are welcome.
Arnor Heidar Sigurdsson @arnorhs on Twitter