Practical Elm for a Busy Developer

You get excited about Elm, so you breeze through the Elm guide, and get a few simple examples running. Then you come up with a great project idea, make a start on it and... things grind to a halt.

Now that you need a real world data model, a sophisticated UI and fully fleshed out interactions, Elm starts to feel truly cryptic and you start getting really frustrated. You want to make progress, but you just keep hitting one brick wall after another.

You start working out how to handle URL changes in your single-page app, and you find the signature for Browser.application:

application :
    { init : flags -> Url -> Key -> ( model, Cmd msg )
    , view : model -> Document msg
    , update : msg -> model -> ( model, Cmd msg )
    , subscriptions : model -> Sub msg
    , onUrlRequest : UrlRequest -> msg
    , onUrlChange : Url -> msg
    }
    -> Program flags model msg

What the hell is this supposed to mean?! What are you supposed to populate all these fields with? You find yourself staring at the docs and trying to reason it out, again and again.

Then you have to write a JSON decoder for nested arrays within objects within arrays:

[{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[173.6522539573263,-42.38837303396274,0],[173.6349550896291,-42.394882761024,0],[173.6333568021225,-42.40815928138313,0],[173.6366404852585,-42.42551304617241,0],[173.6627622447429,-42.43515150117127,0],[173.7003759240009,-42.44530275776406,0],[173.7265410580236,-42.43465018074845,0],[173.7327548095885,-42.42029037855389,0],[173.7151138089028,-42.39800088737382,0],[173.6995170112496,-42.38233600339516,0],[173.6522539573263,-42.38837303396274,0]]]},"properties":{"name":"Polygon","styleUrl":"#m_ylw-pushpin","styleHash":"-37e2b4ca"}}]}, {"type":"FeatureCollection","features":[{...

You spend half a day combining JSON functions this way and that, but you just can't seem to get it right. You start getting a new appreciation for JSON.parse.

Turn your attention to styling your pages, and it threatens to turn into another headache. There are so many options:

- Inline styles
- Separate stylesheet
- elm-css
- elm-bootstrap
- elm-tachyons
- elm-ui
- ...

This doesn't look straightforward! What is the right way to handle styles?

You haven't even got to figuring out ports to do JavaScript interop with that cool chart library, or understanding how to organise your code once you go beyond a handful of pages.

You realise that the change of mindset required to switch to Elm is way broader than you thought. But going back to familiar JavaScript would feel like a defeat.

"I still don't feel like I really understand how to write code in Elm"

I know how that feels. When I first found out about Elm, I was excited by its potential to eliminate runtime errors and make development a more fun experience for my team. I was super motivated to learn it. There were plenty of beginner Elm tutorials, and it's easy to learn the Elm syntax and concepts (it's simple by design after all!).

However, I still found myself flailing when I tried to go beyond the simple counter and TODO list examples, because information available online quickly gets sparse.

There is still a chasm between learning the basic concepts of Elm, and using it to create complex real world applications - the kind that you'd release into production at work.

What if you could skip the frustration of figuring things out from meandering blog posts, scant tutorials, and terse package READMEs?

Practical Elm for a Busy Developer will help you get to the point where writing Elm code feels as comfortable as writing JavaScript.

It will guide you through the practical tasks of creating applications with Elm: building UIs, styling, working with JSON, interacting with JavaScript code, testing and so on. It will also show you the power user features of Elm, beyond the basic syntax.

You will start to benefit from Elm's type system and write reliable, exception-free code.

It will NOT rehash the basics that you can easily pick up from the Elm guide and other online resources: no explaining why functional programming is great, or why we want currying, or what union types are. I don't want to waste your time on stuff you already know.

What does the book cover?

The focus of the book is on practical topics:

  • A discussion of options for creating UIs and styling
  • Approaches and tools for preventing and finding bugs
  • JSON parsing (the most commonly reported problem Elm newcomers face)
  • Making server requests and working with commands
  • JS interop and ports
  • A discussion of code organisation as your application grows
  • An example of integrating a rich editor with the help of custom elements
  • A detailed introduction to elm-ui, a UI package that liberates you from HTML and CSS
  • A discussion of integrating Elm into a JS application
  • An in-depth look at language features such as pattern matching
  • Tools for being more productive when writing Elm code
(I will also send you updates when I publish an Elm related post.)

What do people say about the book?

Here are some of the things people had to say about the book:

"I'm liking the book so far and am looking forward to what you have in store for the rest of the chapters. Being introduced to elm-analyse made me go back to previous projects, start linting them, and add elm-analyse to their build pipelines."

Paul Fioravanti

"What I really appreciate and enjoy in the book is the way you incrementally refactor the application to introduce a different way to model the data that solves the problem. I like when the type system can prevent bugs, and completely eliminate some bugs. I like the way you introduce the sub-update thing. I had to look long and hard at some of Richard Feldman's [SPA example] code to arrive to this conclusion, and spent a long time shouting WTF while trying to understand what was going on. I would have loved to have this chapter back then...

I would definitely recommend your book. I am looking forward to the next chapters about how to use the type system."

Christophe Graniczny

"I’m reading your Elm book and really like it — it answers several questions/problems I was facing. Thank you for writing the book, I really appreciate it!"

— Andreas Pehnack

"While I usually find the Elm documentation on the web excellent, I find the stuff in your book more directly transferrable to real-world tasks. I look forward to reading about saving session IDs to localStorage or Custom Elements, for example. Thanks a lot for your book, I find it a valuable resource."

Andreas Wagner

"Bought your book Practical Elm. Very early into the content, only gotten to page 65 but already had quite a bit clarified. Must say I was sceptical buying your book as I couldn’t find much info about you, you know confs, talks etc but I’m very pleased so far."

Napoleon Ahiable


Feel like you're in the future of frontend development with Elm

You'll be able to glide up the learning curve and enjoy Elm's well thought out simplicity and reliability.

Even if you can't use Elm full time, you will probably find that the "Elm mindset" improves how you develop software in other languages like JavaScript.

And as functional programming is only getting more popular, having an Elm project or two on your CV will also look good when it's time to get a promotion or switch jobs!


Buy Practical Elm

Formats
PDF, Mobi, EPUB

Pages
218

Money back guarantee
30 days

Elm version
0.19

Tons of code samples

Code for sample app included

No rehashing of basics
GET THE BOOK NOW FOR $39
Get your Elm projects off the ground with confidence.
Practical Elm cover

Elm 0.19 and Elm 0.18 editions provided

The book is up to date with Elm 0.19 and packages like mdgriffith/elm-ui (1.1.0), elm-explorations/test (1.2.0) and elm/http (2.0.0). In case you're still using Elm 0.18, I've also included the Elm 0.18 version of the book and sample code in the download.

Note: EPUB & Mobi only suitable for tablets

These versions of the book are formatted for tablets and provided for convenience only. I don't test them extensively, so formatting may be off - in particular, code samples may wrap awkwardly.

Not ready to buy yet?

Check out the sample chapter to see if the style of the book works for you:

(I will also send you updates when I publish an Elm related post.)

About the author

Alex KorbanHi, I'm Alex Korban (@alexkorban). I'm an author and software consultant with an interest in functional programming, databases, and geospatial applications.

I previously co-founded a company to help the heavy construction industry improve safety and productivity when building highways, tunnels, and other infrastructure. We did this by collecting geospatial data via mobiles and Bluetooth beacons, and then analysing and visualising it.

Prior to that I worked on a wide range of software, such as pre-iPhone mobile applications, a flight simulator, GPS-based vehicle fleet tracking, and automatic control software for construction machines (bulldozers, excavators, and self-driving kerb laying machines).

I've also written several books about C++, and a book about working with time in PostgreSQL.

FAQ

What if I'm not happy with the book?

I offer a 30-day money back guarantee, so there is no risk in buying.

What format is the book in?

The book is provided in PDF format, and also EPUB and Mobi. Note, however, that EPUB and Mobi versions are formatted for tablets and provided for convenience only. I don't test them extensively, so formatting may be off - in particular, code samples may wrap awkwardly.

What version of Elm is the book written for?

Elm 0.19.

Will I get updates?

After the Elm 0.19 update is complete, I will update the book if I discover errors, and you will get those updates free.