…and there it was. Bliss.

Never one to back down from a challenge (especially involving literature and creative writing), I have decided to post today’s message as a haiku. After this brief intro, I will break down several new parts of the library, Underscore, with haikus. Because, what’s better than coding and haikus? Only cherry blossom trees and Pikachu…

From “Collections” comes
the truth of these timely tools.
So simple, pristine.

Because of the ability of find to quickly locate the first instance that matches a criteria, I believe it is useful when you are looking only for that first match. This helps with speed and performance since it doesn’t have to go through the whole list to produce results.

In the second example, filter works in a similar way, but yields results for all values - not just the first- that pass a truth test. This is an important difference from find, as it is much more thorough and will be helpful when you need ALL values that match the parameters.

There are “Arrays” that
amaze; worker ants digging
and building their hills.

Flatten is one of my favorite array functions since it “flattens” (or brings all arrays, even those nested within each other) into a single level. This is another way to simplify coding and increase the performance/speed of the code you are working on.

Another array function that I have found to be quite useful is Uniq(or Unique). It uses === to produce an array that does not have any duplicates within it. This is a great way to find specific information, and when coupled with isSorted or iteratee, it has even more functionality.

“Functions” fracturing,
breaking down, reassembling.
Blocks turn to towers.

When a variable is passed into the bind function it makes the value of “this.” the object. Also, by passing arguments through the function, it pre-fills them (this is called a partial application). This is a great tool to write clean code and consolidate functions.

Delay is a much easier function to wrap your head around. By running delay, I am telling the code to wait however long I have placed in the code (1000 = 1 second) before it completes its task. In the above example, that task is to simply communicate ‘logged later’ after one second. This is a great way to keep the code from getting blocked, and controlling the queue.

“Objects” floating down
the river, towards the nether;
curiosity.

mapObject works very similar to .map, but for objects. It can also change the value of each property, and it works with iteratee (which we will get to in a bit) and [context]. While I am still very, very new to programming, I have learned that mapping is a great way to list information and quickly sort through it.

When you use extend it will copy all of the properties from the source object over to the destination object, and then extend will return the destination object. Because it is in-order, the last source will override the properties of the same name in previous arguments. The ability to copy over properties from one object to another is a great way to produce fluidity within the code, cut down on the chance of errors or glitches, and speed up processes.

Whispering stars speak,
plotting a brief course for me
named “Utility”.

One of my favorite utility functions is mixin. It allows you to use your own utility functions within Underscore. In order to do this, you have to add a hash similar to {name: function}. I can see the usefulness of this ability in everyday life as you might be building your own library of functions that you use constantly at your job.

Lastly, iteratee is still a bit of a mystery to me. From what I understand thus far, iteratee allows you to transform your predicates through a plethora of various methods that includes map, find, filter, and many more. In the above example newOz uses iteratee to pull out types from oz and then map produces the array.

Suffice it to say, I am learning more daily than I could have ever imagined. Sometimes it is still overwhelming. But I am beginning to realize there is always an answer; sometimes there are many. The trick isn’t to keep breathing, it’s to keep coding. Well, and to keep breathing. You wouldn’t make it very far if you didn’t take a breath now and then.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.