Skip to content

A collection of Elixir exercises and examples covering fundamental concepts and advanced topics in functional programming.

Notifications You must be signed in to change notification settings

rvega1204/Elixir

Repository files navigation

Elixir Learning Projects

A collection of Elixir exercises and examples covering fundamental concepts and advanced topics in functional programming.

📁 Project Structure

code/
├── closures.exs
├── funcs.exs
├── funcsMath.exs
├── lists.exs
├── maps.exs
├── math.exs
├── modules_maps.exs
├── poker_probabilities.exs
├── range_enum.exs
├── recursion.exs
├── simple.exs
├── tuples.exs
├── part1/              # Additional exercises
└── process_intro/      # Mix project - Process basics
    └── lib/
        └── process_intro/
            └── basics_module.ex

🚀 Getting Started

Prerequisites

  • Elixir 1.19.3 or higher
  • Erlang/OTP 28 or higher

Running Scripts

For standalone scripts in the root directory:

cd code
elixir script_name.exs

Examples:

elixir recursion.exs
elixir poker_probabilities.exs
elixir closures.exs

Running Mix Projects

For the process_intro Mix project:

cd process_intro
iex.bat -S mix

Then call functions interactively:

iex(1)> ProcessIntro.BasicsModule.main()
Inside the main() process (pid): #PID<0.110.0>
:main_done

📚 Topics Covered

Core Fundamentals (Root Scripts)

File Topic Description
simple.exs Basics Introduction to Elixir syntax
funcs.exs Functions Function definitions and calls
closures.exs Closures Anonymous functions and scope
math.exs Mathematics Basic arithmetic operations
funcsMath.exs Math Functions Advanced mathematical functions
lists.exs Lists List operations and transformations
tuples.exs Tuples Tuple manipulation
maps.exs Maps Map data structure
modules_maps.exs Modules Module organization with maps
range_enum.exs Enumerables Ranges and Enum module
recursion.exs Recursion Recursive algorithms
poker_probabilities.exs Applied Math Combinatorics and probability
name_formatter_test.exs Tests Testing functions

Process Intro (Mix Project)

  • Process Basics: Creating and managing processes
  • Message Passing: Inter-process communication
  • Process IDs: Understanding PIDs and self()

🔧 Key Concepts Demonstrated

Recursion Example

Implementations include factorial, n-choose-k, and recursive list processing:

# From recursion.exs
def n_choose_k_helper(n, k) do
  sets_without_x = n_choose_k_helper(n - 1, k)
  sets_with_x = n_choose_k_helper(n - 1, k - 1)
  sets_without_x + sets_with_x
end

Process Management

# From process_intro/lib/process_intro/basics_module.ex
defmodule ProcessIntro.BasicsModule do
  def main() do
    IO.puts("Inside the main() process (pid): #{inspect(self())}")
    :main_done
  end
end

📖 Learning Path

The exercises are designed to progress through:

  1. Basic Syntaxsimple.exs
  2. Functionsfuncs.exs, closures.exs
  3. Data Structureslists.exs, tuples.exs, maps.exs
  4. Algorithmsrecursion.exs, funcsMath.exs
  5. Applied Problemspoker_probabilities.exs
  6. Concurrencyprocess_intro/

🛠️ Development Tips

Running in IEx

# Load a script in IEx
iex script_name.exs

# Or compile and run
elixirc script_name.exs

Recompiling in IEx (for Mix projects)

recompile()

Getting Help

h Enum
h Enum.map

📝 Key Elixir Principles

  • Immutability: Data cannot be changed after creation
  • Pattern Matching: Destructuring and matching values
  • Recursion: Preferred over traditional loops
  • Higher-Order Functions: Functions that accept/return functions
  • Process-Based Concurrency: Lightweight processes for concurrent operations

📚 Resources


  • Author: Ricardo Vega
  • Environment: Windows PowerShell with Elixir 1.19.3 / OTP 28
  • Course: Elixir Programming Fundamentals

About

A collection of Elixir exercises and examples covering fundamental concepts and advanced topics in functional programming.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages