Getting Ready to Play Blackjack and Poker with Elixir Comprehensions

In a lot of languages it’s common to loop over a list with an Enumerable. Though we can do this in Elixir too, Enum can become unwieldy for particular use cases, so we can turn to comprehensions instead. In this video, we go over comprehensions (, which allow us to quickly build and modify lists.

We’ll highlight using generators to create lists, and how multiple generators can come in handy as well. For example, if we wanted to build a deck, we could do so using multiple generators:

ranks = for x <- 2..14, do: x
suits = [:clubs, :hearts, :diamonds, :spades]

deck = for rank <- ranks, suit <- suits, do: %{rank: rank, suit: suit}

After we highlight some use cases, we’ll then walk through filtering as well as uniq, into, and reduce options.

Sign up for our newsletter

Get notified of any new episodes as we release them.

© 2020 QuantLayer, LLC. All rights reserved.