Last active
August 29, 2015 14:15
-
-
Save ds0nt/3e892047d9de25dc13a7 to your computer and use it in GitHub Desktop.
ES6 Generators and Tagged Template Strings in io.js!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
function taggzies () { | |
var strings = arguments[0]; | |
var vals = _.slice(arguments, 1); | |
//ES6 Generator | |
function* val() { | |
var len = vals.length; | |
for (var i = 0; i < len; i++) yield vals[i]; | |
while (true) yield ""; | |
}; | |
// instantiate generator | |
var valgen = val(); | |
return _.reduce(strings, function(prev, v) { | |
return prev + v + valgen.next().value; | |
}, ""); | |
} | |
// tagged template string. | |
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings | |
var output = taggzies`foo ${"pazzaaaz!!"} bar`; | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outputs: abcdefg pazzaaaz!! hijklmnop