Image for post
Image for post

In Elixir there exists two built in modules Enum and Stream. Enum and Stream both give us access to a set of algorithms for working with enumerables. Both also work in linear time (O(n)). In fact, many of the built in functions that can be found in the Enum module, can be found in the Stream module.

Stream and Enum do have their differences however! The biggest difference between the two is the way their algorithms are evaluated. Enum is evaluated eagerly whereas Stream is evaluated lazily. What this means is Stream will wait to evaluate the functions defined using the module until it is explicitly called in someway. …


In Elixir the most used tool for iterating through collections is recursion. Most of us know recursion as referencing a function within its own invocation. This function gets called until it arrives at a base terminating case or after it has been called a fixed number of times. An example of a recursive function in elixir would be as follows:

# 1
def multiply_numbers2([head | tail]) when is_number(head) do
multiply_numbers2(tail) * head
end

# 2
def multiply_numbers2([_head | tail]) do
multiply_numbers2(tail)
end

# 3
def multiply_numbers2([]) do
1
end

The problem with this implementation is that at greater collection sizes, the compiler will have to use a linear amount of memory in order to generate the desired outcome. This is because, as written, each following stack directly relies on the output of the stack before it. As a result, the compiler and the garbage collector must keep each previous stack around until the final terminating function call. …


Phoenix is a modern web framework for the functional programming language Elixir. Phoenix comes shipped with something called Phoenix Channels, a feature of Phoenix that allows for soft real-time communication out of the box.

Channels can be used for:

  • Chat rooms and APIs for messaging apps
  • “Breaking” news (like emergencies or sports info.)
  • Events in games
  • Much more!

Channels may seem intimidating but I hope to demystify whats going on behind the scenes for you!

The structure of a channel is quite simple. At a very high level, channels enable clients to connect to a web server and subscribe to various “topics.” A client then sends and receives messages over its subscribed topics. A client can subscribe to as many topics desired on a single connection, which reduces expensive connections! Awesome! Channels are also transport agnostic which means that two systems, one using long-polling and one using WebSockets, can utilize the same logic. …


In Elixir the for keyword is used differently than most other language. The for keyword starts something called a comprehension in Elixir.

A comprehension is basically syntactic sugar for looping through enumerables in Elixir.

Image for post
Image for post

The first part of the expression, x <- list, is what is known as a generator. They are responsible for “generating” the next value to be called upon by the comprehension. You can have multiple generators, much like you can have nested loops. Comprehension are not just limited to lists. Any enumerable is able to utilize comprehensions.

Comprehensions also have a second piece to them: filters.


While finding a way to capture JWT tokens for a recent project I was working on, I was looking for a way to save the JWT token I was getting in my return promise of my authorization fetch. This lead me down a path of doing research and stumbling across a possible solution to my problem: localStorage. So what is localStorage you ask? Let me tell you.

LocalStorage is a read only property of your DOM’s origin, or the scheme (protocol), host (domain), and port of the URL used to access it. You are able to assign Storage objects places in your DOM’s memory. LocalStorage is very similar to sessionStorage but there is a key difference. While sessionStorage resets every time you leave the page, localStorage has no expiration date. …


While beginning my journey into learning JS after coming from Ruby, I struggled with learning how to properly use JS’ many iterators, especially .map.

The iterator .map is an Array.prototype method that is super useful when you need to perform certain actions on every single element in an array but also preserve the original array. The return value for .map is a new array so it is very easy to get new representations of data by using it.

The syntax of .map is very easy to follow once you are a bit familiar with JS and can be broken down into a few parts. …


On August 13th, two of the world’s leaders in tech began a legal battle that could very well change the landscape of the mobile-app industry. Epic Games filed a lawsuit against Apple in response to Apple removing their globally popular game, Fortnite, from the app store on their IOS devices.

For those who do not know, the Apple App Store, found on all 1.4b+ Apple devices, is the only way to download applications to an Apple device. Apple charges a 30 percent commission on all purchases in the App Store. …


Throughout my first few weeks of learning Ruby, I’ve been bombarded with a ton of new information. While a student at Flatiron School’s software engineering boot-camp, we are given a ton of new information everyday, often compounding on the prior day’s lessons. I began to notice myself building a defense mechanism of only allowing myself to focus on the major topics, not bothering to master minute details like naming conventions. As we progressed I felt my technical skill growing, but I was often given feedback that the names of my variables and methods could use some work. Admittedly, at first I was kind of annoyed by this. If my code worked, who cared that I named something “i” instead of the name of the class I was iterating through? Why did it mater? As we dove deeper into Ruby and began working with Active Record, I began to notice small patterns in naming that could either break or make a line of code. It was only then where I saw how powerful names could actually be in Ruby. …

About

Cody DeMartin

Full-Stack Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store