Day Three - Calm Before the Storm
Some Quick Answers
In Day Two - Import, Alias and More I talked a little bit about DailyDrip.com and some questions I had. Thanks to speedy feedback from Josh, I got my answers. If you’re interested, you can read my review of the service here: DailyDrip Elixir Training Review.
Bite-Sized Learning & Prep Work
Over the next couple of days I’m doing a Node JS workshop, so my time is going to be fairly limited. I’m also getting prepared to start learning Phoenix through a new learning service (review coming).
One of the things I’m starting to get familiar with is MIX, which is a cool build tool for Elixir.
Check out more here: Mix - Elixir Build Tool
Once you setup a project in Mix, you end up with a Mix.exs file. And in that file, you can manage dependencies (reminds me of NPM a little).
For example, to add dependencies, open your Mix.exs file and add them in the deps function like this:
The above code, which is a tuple with an atom and version information, will add the timex package to your dependencies. And according to the docs, Mix is using HEX, which is a package manager, to fetch dependencies.
I actually wasn’t sure where the docs were for versioning (“~>, =, etc”). I went through Mix and Hex docs and eventually found the answer over at the Elixir lang docs. Here are some useful examples:
For more information, check out the Elixir version doc.
Ok, so you’ve added some dependencies, now what?
By adding them to the application function, you can make sure they get loaded when your app starts.
As you can see, you just list the atom for the dependency in a list for applications.
A Little Erlang
I spent time in IEX playing around with Erlang’s Enum.Filter, which filters an enumerable and returns a truthy value.
Here’s a little example that takes a list of numbers, filters them and hands back a list of numbers that are each over 57.
On a side note, I added a string into that list (“lolz”) and it came back after the filter. I was thinking that since it wasn’t an Integer it would just be filtered out.
I then when into IEX and tried this:
So I’m kind of wondering why “lolz” > 27346287346782648762 is true. I’m sure it’s something simple.
update to above string issue: So one thing I was missing is that in Elixir a “string” is a binary. For example:
My To-Do List
From here, I have several items to do over the coming few days for learning and for this site.
- Continue evaluating Daily Drip
- Begin evaluating LearnPhoenix.io
- Get back into (and start review for) Programming in Elixir 1.3
- Explore Mix and Hex a little more – eventually, I want to do a series just on them as I like building tools and package managers.
- Finish up the Red:4 video and finish the review
- Go through this site and make edits
Until next time, keep your functions pure!