Skip to content

Instantly share code, notes, and snippets.

@ds0nt
Last active August 29, 2015 14:15
Show Gist options
  • Save ds0nt/3e892047d9de25dc13a7 to your computer and use it in GitHub Desktop.
Save ds0nt/3e892047d9de25dc13a7 to your computer and use it in GitHub Desktop.
ES6 Generators and Tagged Template Strings in io.js!
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);
@ds0nt
Copy link
Author

ds0nt commented Feb 14, 2015

outputs: abcdefg pazzaaaz!! hijklmnop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment