Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gleamという選択肢

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 Gleamという選択肢

関数型まつり2日目「Gleamという選択肢」のスライドです。

Avatar for Comamoca

Comamoca

June 14, 2025
Tweet

Other Decks in Programming

Transcript

  1. Gleam is Go ideas but from the perspective of a

    FP nerd instead of a C nerd — Louis Pilfold
  2. エラーメッセージの例 error: Unknown variable ┌─ /src/main.gleam:3:8 │ 3 │ echo

    prson │ ^^^^^ Did you mean person? The name prson is not in scope here. warning: Unused variable ┌─ /src/main.gleam:2:7 │ 2 │ let person = "Jhon" │ ^^^^^^ This variable is never used Hint: You can ignore it with an underscore: _person.
  3. 構文 • if とか for がない • コールバックの構文糖(use 構文) •

    ブロック構文 • パターンマッチ • パイプライン演算子
  4. 例えば 1 let val = True 2 case True {

    3 True -> "これは True" 4 False -> "これは False" 5 }
  5. 例えば 1 import gleam/list 2 3 pub fn main() {

    4 list.range(0, 10) 5 |> list.map(fn (n) { n * 2 }) 6 |> list.filter(fn (n) {n % 3 == 0}) 7 |> echo 8 }
  6. ルーティング 1 import gleam/string_tree 2 import hello_world/app/web 3 import wisp.{type

    Request, type Response} 4 5 pub fn handle_request(req: Request) -> Response { 6 // ["tasks", "2"] 7 case wisp.path_segments(req) { 8 [] -> index(req) 9 ["hello"] -> greet(req) 10 ["tasks", id] -> show_task(req, id) 11 _ -> wisp.not_found() 12 } 13 }
  7. ミドルウェア 1 pub fn greet_middleware(req: Request, handler: fn (Request) ->

    Response) -> Response { 2 io.println("Hello!") 3 } 4 5 pub fn handle_request(req: Request) -> Response { 6 use req <- greet_middleware(req) 7 8 case wisp.path_segments(req) { 9 [] -> index(req) 10 _ -> wisp.not_found() 11 } 12 }