Elixir 程式設計
一份全面指南,介紹如何使用 Elixir 進行函數式與並行程式設計。內容涵蓋從物件導向思維轉向函數式思維的過程、模式比對、不可變性、以角色模型實現並行處理,以及運用 OTP 建立穩固的分散式系統。
課程總覽
📚 內容概要
一本全面介紹使用 Elixir 進行函數式與並行程式設計的指南。內容涵蓋從物件導向思維轉換至函數式思考,模式匹配、不可變性、以角色模型實現並行,以及利用 OTP 建立穩健的分散式系統。
透過函數式程式設計的美學,掌握打造韌性並行系統的藝術。
作者: Dave Thomas
致謝: José Valim、Corey Haines、Bruce Tate、Jessica Kerr、Anthony Eden、Chad Fowler、Kim Shrier、Candace Cunningham,以及 Potomac Indexing。
🎯 學習目標
- 比較 Elixir 的資料轉換模型與傳統的狀態驅動程式設計。
- 設定互動式 Elixir shell(IEx),並透過腳本與編譯執行 Elixir 程式碼。
- 使用匹配運算子(
=)、鎖定運算子(^)和萬用字元(_)來解構與驗證資料。 - 解釋不可變性在效能與記憶體管理上的理論與實務影響。
- 認識並運用 Elixir 的內建型別,包括值型別、系統型別與集合型別。
- 應用變數作用域規則與
with表達式,以處理複雜的資料轉換。 - 使用標準語法與捕捉語法(
&)建立與呼叫匿名函數。 - 在模組中使用模式匹配與遞迴實作命名函數,以處理複雜邏輯。
- 使用守衛條件與預設參數來控制函數執行流程。
- 解構與建構列表: 利用頭/尾模式匹配來導航與建立遞迴列表結構。
課程 共 10 课时 · 预计 30.0h
課程
Lesson
This lesson introduces Elixir as a functional language focused on data transformation, emphasizing the importance of immutability and the use of the pipe operator for clean, predictable code. Students will also learn how Elixir’s actor-based concurrency model uses isolated processes and message passing to ensure thread safety and system scalability.
This lesson introduces the functional paradigm of Elixir, focusing on the core concept of data immutability and the use of pattern matching over variable mutation. Students will learn how to perform data transformations to create new values rather than modifying existing ones, ensuring predictable and thread-safe code.
This lesson explores foundational functional programming in Elixir, focusing on anonymous and named functions, module encapsulation, and the use of the pipe operator for data transformation. Students will also learn to leverage pattern matching and the `with` expression to handle complex, multi-step logic safely and effectively.
AI019: Recursive Lists and Data Structures (Lesson 4) explores the recursive nature of linked lists in Elixir, focusing on head-tail decomposition and the implementation of custom recursive functions. Students will learn to identify base cases, utilize the cons operator, and apply recursive patterns to perform efficient list operations.
This lesson explores the differences between greedy processing with the Enum module and lazy processing with the Stream module in Elixir. Students will learn to implement the Enumerable protocol and apply these concepts to perform memory-efficient data transformations and advanced string processing.
This lesson explores advanced Elixir control flow, focusing on pattern matching with case expressions, guard clauses, and the use of the with construct for error handling. Students will also learn to manage project structures using Mix and improve code quality through professional tooling like Credo and Dialyzer.
This lesson explores how to maintain persistent state in Elixir using recursive functions and Tail-Call Optimization (TCO) to keep processes alive. Students will learn to manage process lifecycles, handle message passing, and implement deterministic communication patterns in concurrent systems.
This lesson explores the fundamentals of the Open Telecom Platform (OTP) in Elixir, focusing on how behaviors, supervision trees, and I/O messaging enable the creation of fault-tolerant, distributed applications. Students will learn to implement GenServers and leverage the Error Kernel philosophy to build robust systems that effectively manage process lifecycles and inter-node communication.
This lesson explores advanced OTP architectures and the Five-Question Framework to achieve high-reliability state management in Elixir. Students will learn to design robust supervision trees and distributed systems by systematically defining environment constraints, focal points, and fault-tolerance strategies.
This lesson explores Elixir’s metaprogramming capabilities, focusing on how the language's homoiconic nature allows source code to be treated as data via the Abstract Syntax Tree (AST). Students will learn to design extensible software using protocols and macros while evaluating how static analysis tools like Dialyzer provide type safety without sacrificing dynamic flexibility.