It's been only two weeks ago that December started with all the advent calendars, and in that small time there is so much content to go through which is surreal. In the 49 weeks that I've been writing this newsletter, it's the first time so many articles have been written in just a few weeks.
- Once, twice, three times a value - A very simple intro to Elm's tuples.
- Single-Constructor Custom Types - Aksel describes a neat trick with single-constructor custom types which takes the concept of pattern-matching (also explained in the previous article about records) to the next level to unpack types.
- The power of let expressions - Let expressions allow you to save some space by introducing "variables" into your code. A while ago I have learned that let expressions is a concept that came to Elm from λ-calculus.
- Letting functions in - And in addition to simple variables, you can also create local functions inside the
- Climbing trees - Have you ever seen nested
case..ofexpressions? I have on Github. And I have also written this code myself. But you can easily compress these into a more readable code.
- Simplify your code with ad hoc tuples - Yet another little trick that is useful in your belt
- Peeking Inside Lists - Did you know you could use pattern matching on lists too?
- Hurry, curry! - It's about currying, a concept of partial function application
- Partial application of functions! - And a follow-up to the concept explained in the previous article.
- Lord of the pipes - Pipes are great. Shell pipes are awesome. Yahoo Pipes were revolutionary. And Elm pipes are amazing too.
- Operators are functions, too - Did you know that you could re-write
left ++ rightinto
(++) left right? You could use an operator as a function by wrapping it inside the parentheses. And this is awesome because you can save yourself from creating tiny functions that do these simple things. This article by Robin Heggelund Hansen was a revelation for me.
- What do we do with what's inside the box? - If there is no
undefinedin Elm, what do you do? You use
Nothing, and it's a very powerful construct.
- Combining Maybes in Elm - A tale of combining lots of Maybes together. Spoiler: with Maybe.map
- Reducing boilerplate code in Elm with Maybe.andThen - when using
Maybeyour are required to cover all of the possible cases, otherwise your code will not compile. And to reduce some of that excessive code you can use
andThenwhich runs only if the case doesn't return
- A Bunch of Nothing - that title! It reminds me the famous talk by Lawrence Krauss "A Universe from Nothing" which I highly recommend to watch if you haven't. Elm is great for giving compile-time guarantees (and the absence of
undefined), and the way to work around these in the real world is with
Maybes. Author explains how you would deal with uncertainties in Elm, e.g. if you were provided a list of integers that happened to contain some garbage.
- Greater type safety with opaque types! - a helpful explanation about the use-case for opaque types. If I may mention my Java experience here, opaque types are like getters and setters in Java, i.e. you don't just change the properties of an object directly but do so via defined functions. This helps to keep the implementation details hidden from you, and thus improves the security. You can read more about opaque types from Charlie Koster.
- The Builder Pattern - Elm doesn't allow for optional arguments. Evrything you specify in the function definition must be provided, otherwise you get a compile error. One typical solution for this is to write another function that either calls the first with some provided default, or does a similar thing, just a little bit different. But that is starting to break the KISS principle. So what do you do? The builder pattern to the rescue.
- Let's talk about TEA - The Elm Architecture! - a very good introductory article explaining what the Elm architecture is about (hint: it's a name for model-view-update pattern).
- Remote Data - probably one of the most commonly used patterns in Elm while fetching data over the network.
After reading these 20 short articles on Elm I feel like I've learned to write more idiomatic code in Elm. These short articles are packed with tricks and concepts which are very easy to digest and read in one go.
Kristian Pederson is challenging himself to learn Elm in 30 days: one simple app or component a day. Follow along if you want to learn the basics, or try yourself if you have the time. I've always preferred to build a working project in order to get myself familiar with the new tech. And for Elm I built a simple check-in app to track my winter swimming times. Now that I think of it, I become curious as to what small projects everyone would come up with were they to try a new stack. I am subscribed to Tom Macwright's blog, and his first (as far as I can tell) program in Elm was flair which powers oldfachioned.tech - a website about cocktails. And guys from 47deg wrote about their first experience using Elm and Haskell with GraphQL.
And to finish the last week before Christmas, here's a quote for you from The Dune:
Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.
Have a great week!