Powered by AppSignal & Oban Pro

CRC: input |> construct |> reduce |> convert

class-notes.livemd

CRC: input |> construct |> reduce |> convert

data type definition.

defmodule Counter do
  # construct
  def new(input) do
    String.to_integer(input)
  end

  # reduce
  def add(acc, number) do
    acc + number
  end

  # convert
  def show(acc) do
    "The ants arrrr is #{acc}"
  end
end
input = "42"
import Counter

input 
|> new() 
|> add(1) 
|> add(1) 
|> add(-1) 
|> show()
input = "0"
list_of_numbers = [1, 2, 3]
Enum.reduce(list_of_numbers, Counter.new(input), fn i, acc -> Counter.add(acc, i) end) |> Counter.show()
[first, second, third] = list_of_numbers
input 
|> Counter.new()
|> Counter.add(first)
|> Counter.add(second)
|> Counter.add(third)
|> Counter.show()

Workshop Goals

Topics (ADD)

  • Blind spots
    • [x] mutability
    • [ ] keyword list
    • [ ] sigils
    • [ ] for comprehension
    • [x] strings/charlists
  • OTP and Behavior
    • [x] Base Elixir (counter core)
    • [ ] GenServers
      • [ ] Supervision
      • [ ] Behaviours
  • Phoenix Lifecycle
    • [ ] Endpoints
    • [ ] Application
    • [ ] GraphQL
      - [ ] Batch
  • LLM
    • [x] throw it away
    • [ ] Red/Green indicators
    • [ ] Skills
    • [ ] Usage Rules
    • [ ] Tidewave

Charlists

charlists are a blind spot because Ruby uses both “ and ‘ for strings, but in Elixir they are different!

<<99, 97, ?t>>
[99, 97, 116]
'cat'
"cat" == ~c"cat"
[99, 97, 116]