Andrew's Blfog

Javascript generator functions

It has been a while since my last blog post!

I learned recently about generator functions, having successfully avoided them for over a decade. The basic idea in Javascript is that they are a function that returns a special iterable object. Iterable in this case meaning you can loop over it.


function* generatorFunctionOne () {
    yield "a";
    yield "b";
    yield "c";
    yield "d";
}

const g = generatorFunctionOne();

for (const yieldedItem of g) {
    console.log(yieldedItem);
}

/* 
 * Logs, in order:
 * - a
 * - b
 * - c
 * - d
*/

That's a rather contrived example, but more-or-less shows the base concept - each next call (or each iteration) will continue up to the next yield, and whatever that yield is will be provided as the iterable element, and can be repeated ad nauseum via a loop. So, for example, if you wanted to generate n random numbers...

read more

Version control is a rare tool that I would say is absolutely required, even if you are only using it as a solo developer. Some people say that it's a tool that you live and die by, I agree with that assertion.

~ Robert Venables, September 2009

Version Control is a dummy useful class of software that has helped me out countless times. Atlassian has a pretty good overview of what it is and how it generally works.

For the uninitiated, it's basically where you use a software to semi-manually keep track of changes you make to code, text, or anything really. It will see that a file has changed, you type in a comment to help you remember what you changed, then you save it to a "repository" where you can recall every single change you've recorded. Usually, this repository will be hosted on a server, like or or whatever, but it's not a hard requirement.

read more