{"id":15502526,"url":"https://github.com/matsubara0507/functional-web-development-with-elixir","last_synced_at":"2025-03-28T18:21:48.931Z","repository":{"id":93508278,"uuid":"105987232","full_name":"matsubara0507/functional-web-development-with-elixir","owner":"matsubara0507","description":"The code and solutions from the book Functional Web Development with Elixir, OTP, and Phoenix","archived":false,"fork":false,"pushed_at":"2018-02-28T13:00:32.000Z","size":87,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T18:47:02.759Z","etag":null,"topics":["book-exercises","elixir","phoenix"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matsubara0507.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-06T09:22:03.000Z","updated_at":"2023-10-07T18:50:07.000Z","dependencies_parsed_at":"2023-04-16T04:48:36.649Z","dependency_job_id":null,"html_url":"https://github.com/matsubara0507/functional-web-development-with-elixir","commit_stats":{"total_commits":44,"total_committers":1,"mean_commits":44.0,"dds":0.0,"last_synced_commit":"727894e079b7436004942a93ce95b657350cc4f8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsubara0507%2Ffunctional-web-development-with-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsubara0507%2Ffunctional-web-development-with-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsubara0507%2Ffunctional-web-development-with-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsubara0507%2Ffunctional-web-development-with-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsubara0507","download_url":"https://codeload.github.com/matsubara0507/functional-web-development-with-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246076953,"owners_count":20719897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["book-exercises","elixir","phoenix"],"created_at":"2024-10-02T09:10:10.812Z","updated_at":"2025-03-28T18:21:48.898Z","avatar_url":"https://github.com/matsubara0507.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# functional-web-development-with-elixir\n書籍「Functional Web Development with Elixir, OTP, and Phoenix」の読書進捗管理用リポジトリ\n\n演習の解答などを置いてく．\n\n## About Book\n\n[Elixir](https://elixir-lang.org) と，その Web フレームワーク [Phoenix](http://phoenixframework.org) を用いて関数型プログラミング的な Web 開発を行うことをテーマにした書籍(OTP とは，乱暴な言い方をすれば， [Erlang](https://www.erlang.org) のライブラリ群のようなもの)．\n\nまだ Beta 版で，下記ホームページにて電子書籍でしか販売されてない．\n\n## Links\n\n- [書籍のホームページ](https://pragprog.com/book/lhelph/functional-web-development-with-elixir-otp-and-phoenix)\n- [他の Elixir に関する書籍](https://github.com/sger/ElixirBooks)\n\n## Run\n\nDocker を使ってる\n\n```\n$ docker run -v /c/Users/hoge/functional-web-development-with-elixir:/root/islands p 4000:4000 -it --n\name islands_engine elixir:1.6 /bin/bash\n# cd ~/islands/islands_engine\n# iex -S mix\n```\n\n### Islands_Interface\n\nPhoenix (と Node.js)がいる\n\n```\n$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez\n$ curl -sL https://deb.nodesource.com/setup_6.x | bash -\n$ apt-get install -y nodejs\n$ cd islands_interface\n$ cd assets \u0026\u0026 npm install --no-bin-links\n```\n\n## Contents\n\n公式サイトのは少し古いのかな？\nちょっと違う．\n\n中身を全部ちゃんと読んだわけではないので間違いがあるかも．\n\n(version B5.0)\n\n#### 1. Mapping Our Route\n\n本書の構成について書いてある．\n[この章](https://media.pragprog.com/titles/lhelph/route.pdf)だけは無料で読めるようになっている．\n\n全体としては，Elixir や Phoneix を Web 開発に用いる優位性について感じるために， *Island* という名前のゲームを作成していく．\nPart I では，純粋に Elixir のみでゲームを作る．\nただし，(おそらく) Part I では関数型プログラミングの話に重点があって， Elixir の醍醐味である並行性(*Concurrency*)は出てこない．\n並行性については Part II の OTP の話で導入するそうだ．\nPart III では，Phoenix を使ったもので作り直す(直すかどうかは分からない)．\nただし，[Ecto](https://hexdocs.pm/phoenix/ecto.html)は使わないらしい．\n\nあと，*Island* の説明と，本書のタイトルにもある ***Functional Web Development*** について書いてあった．\nこれ良いこと書いてあります．\n無料で読めるので引用して翻訳(意訳)しとく．\n\n\u003e 関数型プログラミングの最も特徴的なパターンのひとつは(関数)合成です．\n\u003e 関数合成では，大きく複雑な仕事を機能に焦点を当てて小さく切り離し，これらの関数を連鎖(合成)させて完全な振る舞いを再現する．\n\u003e こうすることで，それぞれの関数が小ささが振る舞いの理解を助け，保守を簡単にする．\n\n本書では，この関数プログラミングの考え方を Elixir を用いて Web 開発に適用するそうだ．\n\n### Part I — Define the Functional Core in Elixir\n\n前述したとおり，第一部ではまず，純粋に Elixir のみを使ってゲームを作成する(Phoenixを使わない)．\nアプリケーション(ゲーム)の本質を，*data* と *behavior* を用いて定義する(data と behavior が [Elixir の機能](https://elixir-lang.org/getting-started/typespecs-and-behaviours.html)を指しているのか，値や型のデータと振る舞いという一般用語を指してるのかは，まだよくわからない...)．\nまた，モジュールと関数のみを使って，*逐次的 (Sequential)* な Elixir でアプリケーションの作成を行う(Sequential とは 並行 *Concurrency* の対義語を意味していて，並行に関する機能は使わないという意図だと思う)．\n\n#### 2. Model Data and Behavior\n\n本章ですること\n- Elixir のデータ型としてドメインの要素をモデル化する\n- データ変換として(アプリケーションの)振る舞いを定義する\n\n**(この段落は個人的な主張で少し脱線です)** ○○プログラミングとは結局のところ，プログラムやアプリケーションをどのようにモデル化するかという考え方で，関数型プログラミング(スタイル)は，数学的な関数としてモデル化する．\n数学的な関数には入力の集合と出力の集合があり，プログラミングではその集合をデータ型として表現する．\nまた，複雑な関数は，より小規模でシンプルな関数(データ変換)へ分割し，その関数を合成して複雑な振る舞いを表現する．\n\n本章では，それを Elixir でどう行うかを説明してくれる(らしい)．\n\n#### 3. From Data To State\n\n本章ですること\n- 一時的なプロセスの生成(spawn)\n- 長寿命で状態を持つようなプロセスの生成\n- 状態を保持し変更できるようなエージェントを作成\n- 状態を保持し変更できるような [GenServer](https://elixir-lang.org/getting-started/mix-otp/genserver.html) を作成\n\n第1部では，並行に関する機能は出てこないと思ったが....？？？\nでも，**この章はまだ未完成(“Content to be supplied later.” とのこと)** なのでよくわかりません．\n\nちなみに，本書(もとい Elixir 関連のドキュメント)での *プロセス(process)* という単語は，OS 由来のプロセスでなく，ErlangVM のプロセスを指してると思われる．\n\n#### 4. Manage State with a State Machine\n\n本章ですること\n- ステートマシンの仕組みの概要を知る\n- 状態とトランジションとしてアプリケーションの規則をモデル化する\n- 規則を具体化するためにステートマシンを構築する\n\n今日の Web 開発において，イベントハンドリングや状態の変化は非常に重要なトピックで，これらを Elixir (もとい関数型プログラミング)でどのように表現するか．\nその方法のひとつ(?)がステートマシン，という話っぽいです(読んでみないとよくわからない)．\n\nちなみに，Elixir ではプロセスで保持するデータのことを *state* と呼ぶらしいが，本章では一般的な意味合いで state という単語を用いているらしい．\n\n### Part II — Add OTP for Concurrency and Fault Tolerance\n\n第一部でアプリケーションのコアとなる部分を完成させた．\nそのため，第二部ではいよいよ， *並行性(concurrency)* と *並列性(parallelism)* の世界へと足を踏み入れる．\nOTPは，並行処理のために *GenSrever* を構築し，[フォールトトレランス](http://e-words.jp/w/%E3%83%95%E3%82%A9%E3%83%BC%E3%83%AB%E3%83%88%E3%83%88%E3%83%AC%E3%83%A9%E3%83%B3%E3%82%B9.html)とリカバリーのために *Supervisor* を追加することで，その道へ導く．\n\n#### 5. Wrap It Up In a GenServer\n\n本章ですること\n- ゲームロジックの GenServer を実装する\n- ゲームサーバーのプロセスのパブリックなインターフェースを定義する\n- OTP Behaviour における共通パターンを実践する\n- GenServer を正しい状態で初期化する\n- 個々のゲームに名前を付けるためにプロセスの登録を使用する\n\n#### 6. Process Supervision For Recovery\n\n本章ですること\n- プロセスを開始する様々な方法をより深く見てみる\n- プロセスを監査するための様々な戦略を検討する\n- 粒度のための Supervisor のツリーを構築する\n\nただし，まだ中身は書かれていない(“Content to be supplied later” だそうです)．\n\n### Part III — Add a Web Interface With Phoenix\n\n第一部，第二部でゲームエンジンが完成した．\nそのため，ここからはロジックと Web を介してやり取りをするインターフェースを提供しよう．\nPhoenix はこの要件に対して素晴らしい役割を果たす．\n新しく Phoenix アプリケーションを作成し，ゲームエンジンを依存関係として追加する．\n私たちのゲームエンジンは状態を持つため，Phoenix Channels が提供する永続的な多重接続を利用するのが理想的である．\n\n[Phoenix Channels](https://hexdocs.pm/phoenix/channels.html) は Phoenix が提供する WebSocket のようなステートフルなリアルタイム通信を簡単に扱う機能です(単純な WebSocket ラッパーではなく，それ以上の機能を持ち，WebSocket を使う必要もな無いらしい)．\nPhoenix の目玉機能の一つだそうだ．\n\n#### 7. Generate a New Web Interface With Phoenix\n\n本章ですること\n- 新しい Phoenix アプリケーションの作成(ただし Ecto は抜きで)\n- 依存関係として作成したゲームエンジンを持ち込む\n- Web インターフェイスの監視ツリーにゲームエンジンを組み込む\n\nEcto 抜きの理由は分からない(読めばわかる？)\n\n#### 8. Create Persistent Connections With Phoenix Channels\n\n本章ですること\n- GenSrver と直接通信する Channel を作成する\n- ひとつの GenServer に通信を集中させるために [“topic:subtopic” 規約](https://hexdocs.pm/phoenix/channels.html#topics)を使用する\n- 各ゲームコマンドごとに別々の `handle_in` イベントを定義する — `new game`, `join game`, `fire shot`, などなど\n- コンソールで私たちの Channel とやり取りして動作するようにする\n\n### A1. Testing\n\nまだ何も書かれていない(“Content to be supplied later” だそうです)．\n\n### A2. Installing System Dependencies\n\nまだ何も書かれていない(“Content to be supplied later” だそうです)．\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsubara0507%2Ffunctional-web-development-with-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsubara0507%2Ffunctional-web-development-with-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsubara0507%2Ffunctional-web-development-with-elixir/lists"}