Creating and Using Protocols - Elixir Episode 14

Creating and Using Protocols - Elixir Episode 14

In this video training, you'll learn how to create and use protocols in Elixir. Protocols are a mechanism to achieve polymorphism in Elixir when you want behavior to vary depending on the data type.

In this video training, you'll learn how to create and use protocols in Elixir.

Protocols are a mechanism to achieve polymorphism in Elixir when you want behavior to vary depending on the data type. We are already familiar with one way of solving this type of problem: via pattern matching and guard clauses. Consider a simple utility module that would tell us the type of input variable:

defmodule Utility do
def type(value) when is_binary(value), do: "string"
def type(value) when is_integer(value), do: "integer"
# ... other implementations ...
end

If the use of this module were confined to your own project, you would be able to keep defining new type/1 functions for each new data type. However, this code could be problematic if it were shared as a dependency by multiple apps because there would be no easy way to extend its functionality.

elixir

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Why Learn Elixir in 2020? — Elixir Tutorial for Beginners

How to learn Elixir Phoenix quickly and efficiently in 2020? There's no one perfect way but we can recommend ours. Here's our Elixir tutorial for beginners.

Learn How to Use Recursion in Elixir - Elixir Episode 7

In this video training, you'll learn how to use Recursion in Elixir. Due to immutability, loops in Elixir (as in any functional programming language) are written differently from imperative languages.

Learn How to Use Elixir Modules and Functions - Elixir Episode 6

In this video training, you'll learn how to use Elixir Modules and Functions. In Elixir we group several functions into modules. In order to create our own modules in Elixir, we use the defmodule macro.

Learn How to Use Basic Operators in Elixir - Elixir Episode 3

In this video training, you'll learn how to use Basic Operators in Elixir. Elixir provides the following built-in operators that are defined as functions that can be overridden.

Learn About Elixir Basic Data Types - Elixir Episode 2

In this video training, you'll learn about Elixir basic data types. In this video we will learn more about Elixir basic types: integers, floats, booleans, atoms, strings, lists and tuples.