Learning about Elm made me borrow some concepts into other languages. Elm also opened the world of functional programming to me. I knew some bits of it from Python too but never relied on it heavily. Elm changed that too. I recently stumbled upon
I must say that until recently I didn't know the term "debouncing function". I did intuitively implement them on few occasions, but I never knew the theory, which would have saved me from many embarrassing moments.
Assume you have a search form with auto-complete functionality. Every time a user types a character you want to present them with preliminary results. But if the user types a long sentence you don't want to send a request for each character typed only to dismiss the results because several more characters have been typed already while the code was waiting for response. As such, you want to have some graceful period of time until the input is considered "stable" enough to warrant an action. This is where debouncing comes into play: you specify the wait time after which your function fires. Do not confuse it with the throttling function which is guaranteed to fire at certain intervals of time.
There are quite a lot of packages for Elm already. I liked the simplicity of
grotsev/elm-debouncer. The code is very easy to understand: every time there is an event (e.g. user typing), a counter is incremented and we delay a function which then gets executed after a timeout and checks if the counter is zero. If it is, it runs our code, if not, the counter is decremented. This is obviously a very simplified package, and if you need something more complicated, e.g. cancel the execution of the delay function midway, take a look at another package.
If you're into 3D, Ian Mackenzie has just published version 1.0.0 of his 3D rendering engine for Elm. Here is the announcement. I suggest you also browse his public repos on Github as there are several amazing packages, one of which is
ianmackenzie/elm-geometry. The documentation, examples, and the code are a joy to look at.
Quote of the week
It took less than an hour to make the atoms, a few hundred million years to make the stars and planets, but five billion years to make man!
By George Gamow from "The Creation of the Universe"