Following on from my previous solution to implementing the Bubble-sort algorithm in Clojure, I thought it would be interesting to experiment with a different approach.
Taking advantage of lists and vectors respective cheap head and tail insertions, we can use these two properties to good effect as shown below.
Following on with my exploration into implementing common sorting algorithms in Clojure, today we have the Bubble-sort.
This sort works by iteratively passing through the supplied sequence, swapping the current element with the next if it is comparably greater.
The operation is complete when a pass through the sequence does not result in a swap occurring.
I have been writing a lot about Promises in JavaScript the past couple of weeks.
What happens however, when you wish to use an asynchronous function which does not return a Promise, such as those found in Node?
It is actually pretty simple to abstract away the error-first asynchronous function callback into a Promise we can handle.
In a previous article I demonstrated how a new feature from ES2016 (async/await functions) could be used to help coordinate promises and execution.
However, we are instead able to use Generators (introduced in ES2015) to provide this feature, minus the syntactic sugar these two new keywords provide.