Elixirで言語処理100本ノックやってみた！vol.2

こんにちは！
ElixirSchool教育事業部、事業責任者のこーへーです。
※今回は、口調が勇者風です。

諸君、プログラミングを始めるのに遅いことなんてない。なぜなら私は、30歳を過ぎてからプログラミングに挑戦した、そう、生ける伝説なのである。
ただ、注意がある。いいか、30を過ぎてからプログラミングを始めるなんでぶっちゃけキツい。だから、間違った選択をしないように教えてあげよう。Elixirをやるがいい。

はい、ということで、今日もElixirで100本ノックやっていきましょう。
[100本ノックの記事はこちら](https://nlp100.github.io/ja/ch01.html)

言語処理100本ノックの記事を上から順にやっていく。今日は０２番。

### 02. 「パトカー」＋「タクシー」の文字を先頭から交互に連結して文字列「パタトクカシーー」を得よ

- tx1変数に["タ", "ク", "シ", "ー"]を束縛
```
iex(112)> tx1
["タ", "ク", "シ", "ー"]
```

- 変数pc1に["パ", "ト", "カ", "ー"]を束縛
```
iex(113)> pc1
["パ", "ト", "カ", "ー"]
```

- Enum.zip_with関数を使って、それぞれの変数を無名関数へ渡して、文字列結合
```
iex(114)> Enum.zip_with(pc1, tx1, fn x, y -> x <> y end)
["パタ", "トク", "カシ", "ーー"]
```

- |>(パイプ)でEnum.joinを繋げて、「パタトクカシーー」の完成！
```
iex(116)> Enum.zip_with(pc1, tx1, fn x, y -> x <> y end) |> Enum.join 
"パタトクカシーー"
```

 ### 舞台裏
 エラーだしまくったり、とんちんかんなことをやっているので読む価値はないですが、綺麗に一発でプログラムを実現しているわけではないということを伝えたかったです(∵`)
```
iex(9)> pt
"パトカータクシー"
```

```
iex(10)> pt_st
["パ", "ト", "カ", "ー", "タ", "ク", "シ", "ー"]
```

```
iex(11)> Enum.at(pt_st, 1)
"ト"
```

```
iex(12)> Enum.at(pt_st, 1) |> (2)
** (ArgumentError) cannot pipe Enum.at(pt_st, 1) into 2, can only pipe into local calls foo(), remote calls Foo.bar() or anonymous function calls foo.()
    (elixir 1.15.6) lib/macro.ex:386: Macro.pipe/3
    (stdlib 5.0.2) lists.erl:1594: :lists.foldl/3
    (elixir 1.15.6) expanding macro: Kernel.|>/2
    iex:12: (file)
```

```
iex(12)> Enum.at(pt_st, 1) |> Enum.at(2)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "ト" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:230: Enumerable.slice/1
    (elixir 1.15.6) lib/enum.ex:4459: Enum.slice_forward/4
    (elixir 1.15.6) lib/enum.ex:476: Enum.at/3
    iex:12: (file)
```

```
iex(12)>  equal = Enum.at(pt_st, 1)
"ト"
```

```
iex(13)> pc = "パトカー" 
"パトカー"
```

```
iex(14)> tx = "タクシー"
"タクシー"
```

```
iex(15)> Enum.codepoints(pc)
** (UndefinedFunctionError) function Enum.codepoints/1 is undefined or private
    (elixir 1.15.6) Enum.codepoints("パトカー")
    iex:15: (file)
```

```
iex(15)> String.codepoints(pc)
["パ", "ト", "カ", "ー"]
```

```
iex(16)> pc1 = String.codepoints(pc)
["パ", "ト", "カ", "ー"]
```

```
iex(17)> tx1 = String.codepoints(tx)
["タ", "ク", "シ", "ー"]
```

```
iex(18)> Enum.at(pc1, 0)
"パ"
```

```
iex(19)> pc1 |> Enum.at(0)  
"パ"
```

```
iex(20)> pc1 |> Enum.at(0) |> Enum.ta(1) 
** (UndefinedFunctionError) function Enum.ta/2 is undefined or private. Did you mean:

      * take/2

    (elixir 1.15.6) Enum.ta("パ", 1)
    iex:20: (file)
```

```
iex(20)> pc1 |> Enum.at(0) |> Enum.at(1)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:230: Enumerable.slice/1
    (elixir 1.15.6) lib/enum.ex:4459: Enum.slice_forward/4
    (elixir 1.15.6) lib/enum.ex:476: Enum.at/3
    iex:20: (file)
```

```
iex(20)> pc2 =n pc1 |> Enum.at(0)       
error: undefined function n/1 (there is no such import)
  iex:20

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(20)> pc2 = pc1 |> Enum.at(0) 
"パ"
```

```
iex(21)> pc
"パトカー"
```

```
iex(22)> pc1
["パ", "ト", "カ", "ー"]
```

```
iex(23)> tx1
["タ", "ク", "シ", "ー"]
```

```
iex(24)> pc1 ++ tx1
["パ", "ト", "カ", "ー", "タ", "ク",
 "シ", "ー"]
 ```

 ```
iex(25)> pc1
["パ", "ト", "カ", "ー"]
```

```
iex(26)> tx1
["タ", "ク", "シ", "ー"]
```

```
iex(27)> Enum.reverse_slice([1, 2, 3, 4, 5, 
6], 2, 4)
[1, 2, 6, 5, 4, 3]
```

```
iex(28)> Enum.reverse_slice([1, 2, 3, 4, 5, 
6], 1, 2)
[1, 3, 2, 4, 5, 6]
```

```
iex(29)> Enum.reverse_slice([1, 2, 3, 4, 5, 
6], 0, 1)
[1, 2, 3, 4, 5, 6]
```

```
iex(30)> Enum.reverse_slice([1, 2, 3, 4, 5, 
6], 1, 2)
[1, 3, 2, 4, 5, 6]
```

```
iex(31)> Enum.reverse_slice([1, 2, 3, 4, 5, 
6], 1, 3)
[1, 4, 3, 2, 5, 6]
```

```
iex(32)> Enum.all?(pc1)
true
iex(33)> Enum.all?(pc1, nil, 1)
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(["パ", "ト", "カ", "ー"], nil, 1)
    iex:33: (file)
```

```
iex(33)> Enum.all?(pc1, nil, 2)
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(["パ", "ト", "カ", "ー"], nil, 2)
    iex:33: (file)
```

```
iex(33)> Enum.all?(pc1, 1, 2)  
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(["パ", "ト", "カ", "ー"], 1, 2)
    iex:33: (file)
```

```
iex(33)> Enum.all?(pc1, "パ", 0))
** (SyntaxError) iex:33:23: unexpected token: )
    |
 33 | Enum.all?(pc1, "パ", 0))
    |                       ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(33)> Enum.all?(pc1, "パ", 0) 
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(["パ", "ト", "カ", "ー"], "パ", 0)
    iex:33: (file)
```

```
iex(33)> Enum.all?(1, nil, 1)   
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(1, nil, 1)
    iex:33: (file)
```

```
iex(33)> Enum.all?(1, nil, 3)
** (UndefinedFunctionError) function Enum.all?/3 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all?(1, nil, 3)
    iex:33: (file)
```

```
iex(33)> Enum.all?([1, nil, 3])
false
```

```
iex(34)> Enum.all?([1, nil, 2])
false
```

```
iex(35)> Enum.all?([1, nil, 1])
false
```

```
iex(36)> Enum.all?([1, 1, 1])  
true
```

```
iex(37)> Enum.all?([1, 1, nil])
false
```

```
iex(38)> Enum.all?([1, 1, nil])
false
```

```
iex(39)> Enum.all?([2, 3, 5], fn n -> rem(x,
 2) == 0 end)
error: undefined variable "x"
  iex:39

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(39)> Enum.all?([2, 3, 5], fn n -> rem(n,
 2) == 0 end)
false
```

```
iex(40)> Enum.all?([2, 3, 5], fn n -> rem(n,
 2) == 4 end)
false
```

```
iex(41)> Enum.all?([2, 3, 5], fn n -> rem(n,
 2) == 10 end)
false
```

```
iex(42)> Enum.all([2, 3, 5], fn n -> rem(n, 
2) == 10 end) 
** (UndefinedFunctionError) function Enum.all/2 is undefined or private. Did you mean:

      * all?/1
      * all?/2

    (elixir 1.15.6) Enum.all([2, 3, 5], #Function<42.125776118/1 in :erl_eval.expr/6>)
    iex:42: (file)
```

```
iex(42)> Enum.all?([2, 3, 5], fn n -> rem(n,
 2) == 1 end) 
false
```

```
iex(43)> Enum.all?([], fn _ -> nil end)
true
```

```
iex(44)> Enum.any?([false, false, false])
false
```

```
iex(45)> Enum.any?([false, false, true]) 
true
```

```
iex(46)> Enum.at[2, 3, 5], 2) 
** (SyntaxError) iex:46:20: unexpected token: )
    |
 46 | Enum.at[2, 3, 5], 2)
    |                    ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(46)> Enum.at([2, 3, 5], 2)
5
```

```
iex(47)> Enum.at([2, 3, 5], 2, :none)
5
```

```
iex(48)> Enum.at([2, 3, 5], 5, :none)
:none
```

```
iex(49)> Enum.chunk_by([1, 2, 3, 4, 4, 5, 6,
 7, 8, 9], &(rem(&1, 2) == 1))
[
  [1],
  [2],
  [3],
  [4, 4],
  [5],
  [6],
  ~c"\a",
  ~c"\b",
  ~c"\t"
]
```

```
iex(50)> Enum.chunk_by([1, 2, 3, 4, 4, 5], &
(rem(&1, 2) == 1))            
[[1], [2], [3], [4, 4], [5]]
```

```
iex(51)> Enum.chunk_every(pc1 ,count)
error: undefined variable "count"
  iex:51

** (CompileError) cannot compile code (errors have been logged)

iex(51)> Enum.chunk_every([1, 3] ,count)
error: undefined variable "count"
  iex:51

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(51)> Enum.chunk_every([1, 2, 3, 4, 5, 6]
, 2)
[[1, 2], [3, 4], [5, 6]]
iex(52)> Enum.chunk_every([1, 2, 3, 4, 5, 6]
, 3)
[[1, 2, 3], [4, 5, 6]]
```

```
iex(53)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3)4
** (SyntaxError) iex:53:40: syntax error before: "4"
    |
 53 | Enum.chunk_every([1, 2, 3, 4, 5, 6], 3)4
    |                                        ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(53)> Enum.chunk_every(pc1, 2
...(53)> )
[["パ", "ト"], ["カ", "ー"]]
iex(54)> Enum.chunk_every(pc1, 1)
[["パ"], ["ト"], ["カ"], ["ー"]]
iex(55)> Enum.chunk_evey(pc1, 1, 2)
** (UndefinedFunctionError) function Enum.chunk_evey/3 is undefined or private. Did you mean:

      * chunk_by/2
      * chunk_every/2
      * chunk_every/3
      * chunk_every/4
      * chunk_while/4

    (elixir 1.15.6) Enum.chunk_evey(["パ", "ト", "カ", "ー"], 1, 2)
    iex:55: (file)
```

```
iex(55)> Enum.chunk_evey(pc1, 1, 2, :discard)
** (UndefinedFunctionError) function Enum.chunk_evey/4 is undefined or private. Did you mean:

      * chunk_by/2
      * chunk_every/2
      * chunk_every/3
      * chunk_every/4
      * chunk_while/4

    (elixir 1.15.6) Enum.chunk_evey(["パ", "ト", "カ", "ー"], 1, 2, :discard)
    iex:55: (file)
```

```
iex(55)> Enum.chunk_evey(pc1, 1,, :discard)  
** (SyntaxError) iex:55:24: syntax error before: ','
    |
 55 | Enum.chunk_evey(pc1, 1,, :discard)
    |                        ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(55)> Enum.chunk_evey(pc1, 1, :discard) 
** (UndefinedFunctionError) function Enum.chunk_evey/3 is undefined or private. Did you mean:

      * chunk_by/2
      * chunk_every/2
      * chunk_every/3
      * chunk_every/4
      * chunk_while/4

    (elixir 1.15.6) Enum.chunk_evey(["パ", "ト", "カ", "ー"], 1, :discard)
    iex:55: (file)
```

```
iex(55)> Enum.chunk_evey(pc1, 2, 3 :discard)
** (SyntaxError) iex:55:27: syntax error before: discard
    |
 55 | Enum.chunk_evey(pc1, 2, 3 :discard)
    |                           ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(55)> Enum.chunk_evey(pc1, 3, 2 :discard)
** (SyntaxError) iex:55:27: syntax error before: discard
    |
 55 | Enum.chunk_evey(pc1, 3, 2 :discard)
    |                           ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(55)> Enum.chunk_evey(pc1, 3, 2 :discard)
** (SyntaxError) iex:55:27: syntax error before: discard
    |
 55 | Enum.chunk_evey(pc1, 3, 2 :discard)
    |                           ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(55)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 2)
[[1, 2], [3, 4], [5, 6]]
```

```
iex(56)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 2)
[[1, 2], [3, 4], [5, 6]]
```

```
iex(57)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3, 2, :discard)
[[1, 2, 3], [3, 4, 5]]
```

```
iex(58)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3, 2, :discard)
[[1, 2, 3], [3, 4, 5]]
```

```
iex(59)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 1, 2, :discard)
[[1], [3], [5]]
```

```
iex(60)> Enum.chunk_every([1, 2, 3], 1, 2, :discard)         
[[1], [3]]
```

```
iex(61)> Enum.chunk_every([1, 2, 3], 1, :discard)   
** (FunctionClauseError) no function clause matching in Enum.chunk_every/4    
    
    The following arguments were given to Enum.chunk_every/4:
    
        # 1
        [1, 2, 3]
    
        # 2
        1
    
        # 3
        :discard
    
        # 4
        []
    
    Attempted function clauses (showing 1 out of 1):
    
        def chunk_every(enumerable, count, step, leftover) when is_integer(count) and count > 0 and is_integer(step) and step > 0
    
    (elixir 1.15.6) lib/enum.ex:547: Enum.chunk_every/4
    iex:61: (file)
```

```
iex(61)> Enum.chunk_every([1, 2, 3], 0, 1, :discard)
** (FunctionClauseError) no function clause matching in Enum.chunk_every/4    
    
    The following arguments were given to Enum.chunk_every/4:
    
        # 1
        [1, 2, 3]
    
        # 2
        0
    
        # 3
        1
    
        # 4
        :discard
    
    Attempted function clauses (showing 1 out of 1):
    
        def chunk_every(enumerable, count, step, leftover) when is_integer(count) and count > 0 and is_integer(step) and step > 0
    
    (elixir 1.15.6) lib/enum.ex:547: Enum.chunk_every/4
    iex:61: (file)
```

```
iex(61)> Enum.chunk_every([1, 2, 3, 4], 1, 2 :discard)
** (SyntaxError) iex:61:37: syntax error before: discard
    |
 61 | Enum.chunk_every([1, 2, 3, 4], 1, 2 :discard)
    |                                     ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(61)> Enum.chunk_every([1, 2, 3, 4], 1, 2, :discard)
[[1], [3]]
```

```
iex(62)> Enum.chunk_every([1, 2, 3, 4, 5, 6, 7, 8], 3, 2, :discard)
[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
```

```
iex(63)> Enum.chunk_every([1, 2, 3, 4, 5, 6, 7, 8], 3, 2)          
[[1, 2, 3], [3, 4, 5], [5, 6, 7], ~c"\a\b"]
```

```
iex(64)> Enum.chunk_every([1, 2, 3, 4, 5, 6], 3, 2, [7])
[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
```

```
iex(65)> Enum.chunk_every([1, 2, 3, 4], 3, 3, [])
[[1, 2, 3], [4]]
```

```
iex(66)> Enum.chunk_every([1, 2, 3, 4], 3, 3)    
[[1, 2, 3], [4]]
```

```
iex(67)> Enum.chunk_every([1, 2, 3, 4], 3)   
[[1, 2, 3], [4]]
```

```
iex(68)> Enum.count(pc1)
4
```

```
iex(69)> Enum.concat(left, right)
error: undefined variable "left"
  iex:69

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(69)> Enum.count_until(pc1, 1)
1
```

```
iex(70)> Enum.count_until(pc1, 5)
4
```

```
iex(71)> Enum.count_until(pc1, 0) 
** (FunctionClauseError) no function clause matching in Enum.count_until/2    
    
    The following arguments were given to Enum.count_until/2:
    
        # 1
        ["パ", "ト", "カ", "ー"]
    
        # 2
        0
    
    Attempted function clauses (showing 1 out of 1):
    
        def count_until(enumerable, limit) when is_integer(limit) and limit > 0
    
    (elixir 1.15.6) lib/enum.ex:755: Enum.count_until/2
    iex:71: (file)
```

```
iex(71)> Enum.count_until(pc1, 4) == 4
true
```

```
iex(72)> Enum.count_until(pc1, 3) == 3
true
```

```
iex(73)> Enum.count_until(pc1, 3) == 5
false
```

```
iex(74)> Enum.count_until(pc1, 5) == 5
false
```

```
iex(75)> Enum.count_until(pc1, fn n -> rem(n, 2) == "パ" end)
** (FunctionClauseError) no function clause matching in Enum.count_until/2    
    
    The following arguments were given to Enum.count_until/2:
    
        # 1
        ["パ", "ト", "カ", "ー"]
    
        # 2
        #Function<42.125776118/1 in :erl_eval.expr/6>
    
    Attempted function clauses (showing 1 out of 1):
    
        def count_until(enumerable, limit) when is_integer(limit) and limit > 0
    
    (elixir 1.15.6) lib/enum.ex:755: Enum.count_until/2
    iex:75: (file)
```

```
iex(75)> Enum.dedup(pc1)
["パ", "ト", "カ", "ー"]
```

```
iex(76)> Enum.drop_every(pc1, 1)
[]
```

```
iex(77)> pc1
["パ", "ト", "カ", "ー"]
```

```
iex(78)> Enum.drop_every(pc1, 0)
["パ", "ト", "カ", "ー"]
```

```
iex(79)> Enum.each(pc1)
** (UndefinedFunctionError) function Enum.each/1 is undefined or private. Did you mean:

      * each/2

    (elixir 1.15.6) Enum.each(["パ", "ト", "カ", "ー"])
    iex:79: (file)
```

```
iex(79)> Enum.each(pc1, 1)
** (BadFunctionError) expected a function, got: 1
    (elixir 1.15.6) lib/enum.ex:984: Enum."-each/2-lists^foreach/1-0-"/2
    iex:79: (file)
```

```
iex(79)> Enum.each(pc1, fn x -> IO.puts(x) end)
パ
ト
カ
ー
:ok
```

```
iex(80)> Enum.empty?([])
true
```

```
iex(81)> Enum.empty?(pc1)
false
```

```
iex(82)> Enum.empty(pc1) 
** (UndefinedFunctionError) function Enum.empty/1 is undefined or private. Did you mean:

      * empty?/1

    (elixir 1.15.6) Enum.empty(["パ", "ト", "カ", "ー"])
    iex:82: (file)
iex(82)> Enum.fetch(pc1, 1)
{:ok, "ト"}
```

```
iex(83)> Enum.fetch(pc1, 0) |> Enum.fetch(tx1, 0)
** (UndefinedFunctionError) function Enum.fetch/3 is undefined or private. Did you mean:

      * fetch/2

    (elixir 1.15.6) Enum.fetch({:ok, "パ"}, ["タ", "ク", "シ", "ー"], 0)
    iex:83: (file)
```

```
iex(83)> tx1
["タ", "ク", "シ", "ー"]
```

```
iex(84)> Enum.fetch!(tx1) 
** (UndefinedFunctionError) function Enum.fetch!/1 is undefined or private. Did you mean:

      * fetch!/2

    (elixir 1.15.6) Enum.fetch!(["タ", "ク", "シ", "ー"])
    iex:84: (file)
```

```
iex(84)> Enum.fetch!(tx1, 1)
"ク"
```

```
iex(85)> Enum.filter(pc1, fn n -> n["パ"] == "パ" end
...(85)> )
** (FunctionClauseError) no function clause matching in Access.get/3    
    
    The following arguments were given to Access.get/3:
    
        # 1
        "パ"
    
        # 2
        "パ"
    
        # 3
        nil
    
    Attempted function clauses (showing 6 out of 6):
    
        def get(%module{} = container, key, default)
        def get(map, key, default) when is_map(map)
        def get(list, key, default) when is_list(list) and is_atom(key)
        def get(list, key, _default) when is_list(list) and is_integer(key)
        def get(list, key, _default) when is_list(list)
        def get(nil, _key, default)
    
    (elixir 1.15.6) lib/access.ex:307: Access.get/3
    iex:85: (file)
    iex:85: (file)
```

```
iex(85)> Enum.filter(pc1, fn n -> n["パ"] == ["パ"] end)
** (FunctionClauseError) no function clause matching in Access.get/3    
    
    The following arguments were given to Access.get/3:
    
        # 1
        "パ"
    
        # 2
        "パ"
    
        # 3
        nil
    
    Attempted function clauses (showing 6 out of 6):
    
        def get(%module{} = container, key, default)
        def get(map, key, default) when is_map(map)
        def get(list, key, default) when is_list(list) and is_atom(key)
        def get(list, key, _default) when is_list(list) and is_integer(key)
        def get(list, key, _default) when is_list(list)
        def get(nil, _key, default)
    
    (elixir 1.15.6) lib/access.ex:307: Access.get/3
    iex:85: (file)
    iex:85: (file)
```

```
iex(85)> Enum.zip(pc1, fn x, y -> x <> y end)
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a bitstring

    :erlang.bit_size({:halt, []})
    (stdlib 5.0.2) eval_bits.erl:114: :eval_bits.eval_exp_field1/9
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x, y -> x <> y end)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x -> x == "パ" end)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x -> x == ["パ"] end)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x -> x == ["パトカー"] end)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x, y, z, a -> x <> y <> z <> a == "パトカー" end) 
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_with(pc1, fn x, y, z, a -> x <> y <> z <> a == ["パトカー"] end)
** (Protocol.UndefinedError) protocol Enumerable not implemented for "パ" of type BitString
    (elixir 1.15.6) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.6) lib/enum.ex:166: Enumerable.reduce/3
    (stdlib 5.0.2) lists.erl:1686: :lists.foreach_1/2
    (elixir 1.15.6) lib/stream.ex:1372: Stream.do_zip_enum/4
    (elixir 1.15.6) lib/enum.ex:4041: Enum.zip_reduce/3
    (elixir 1.15.6) lib/enum.ex:3975: Enum.zip_with/2
    iex:85: (file)
```

```
iex(85)> Enum.zip_reduce(
...(85)> pc1)   
** (UndefinedFunctionError) function Enum.zip_reduce/1 is undefined or private. Did you mean:

      * zip_reduce/3
      * zip_reduce/4

    (elixir 1.15.6) Enum.zip_reduce(["パ", "ト", "カ", "ー"])
    iex:85: (file)
```

```
iex(85)> pc1
["パ", "ト", "カ", "ー"]
```

```
iex(86)> tx1
["タ", "ク", "シ", "ー"]
```

```
iex(87)> Enum.zip(pc1, [:a, :b, :c]) 
[{"パ", :a}, {"ト", :b}, {"カ", :c}]
```

```
iex(88)> Enum.with_index(pc1)
[{"パ", 0}, {"ト", 1}, {"カ", 2}, {"ー", 3}]
```

```
iex(89)> Enum.unzip(pc1)
** (FunctionClauseError) no function clause matching in Enum.unzip/3    
    
    The following arguments were given to Enum.unzip/3:
    
        # 1
        ["ー", "カ", "ト", "パ"]
    
        # 2
        []
    
        # 3
        []
    
    Attempted function clauses (showing 2 out of 2):
    
        defp unzip([{el1, el2} | reversed_list], list1, list2)
        defp unzip([], list1, list2)
    
    (elixir 1.15.6) lib/enum.ex:3795: Enum.unzip/3
    iex:89: (file)
```

```
iex(89)> list = Enum.with_index(pc1)
[{"パ", 0}, {"ト", 1}, {"カ", 2}, {"ー", 3}]
```

```
iex(90)> Enum.unzip(list)
{["パ", "ト", "カ", "ー"], [0, 1, 2, 3]}
```

```
iex(91)> Enum.uniq_by(pc1)
** (UndefinedFunctionError) function Enum.uniq_by/1 is undefined or private. Did you mean:

      * uniq_by/2

    (elixir 1.15.6) Enum.uniq_by(["パ", "ト", "カ", "ー"])
    iex:91: (file)
iex(91)> Enum.uniq(pc1)
["パ", "ト", "カ", "ー"]
iex(92)> Enum.to_list(pc1)
["パ", "ト", "カ", "ー"]
iex(93)> Enum.take_every(pc1, 1)
["パ", "ト", "カ", "ー"]
iex(94)> Enum.take_every(pc1, 2)
["パ", "カ"]
iex(95)> Enum.take(pc1, 2) 
["パ", "ト"]
```

```
iex(96)> Enum.split_with(pc1, fn x -> x == x["パ, ト, カ, ー"] end)
** (FunctionClauseError) no function clause matching in Access.get/3    
    
    The following arguments were given to Access.get/3:
    
        # 1
        "パ"
    
        # 2
        "パ, ト, カ, ー"
    
        # 3
        nil
    
    Attempted function clauses (showing 6 out of 6):
    
        def get(%module{} = container, key, default)
        def get(map, key, default) when is_map(map)
        def get(list, key, default) when is_list(list) and is_atom(key)
        def get(list, key, _default) when is_list(list) and is_integer(key)
        def get(list, key, _default) when is_list(list)
        def get(nil, _key, default)
    
    (elixir 1.15.6) lib/access.ex:307: Access.get/3
    iex:96: (file)
    iex:96: (file)
```

```
iex(96)> Enum.split_with(pc1, fn x -> x == ["パ, ト, カ, ー"] end) 
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(97)> Enum.split_with(pc1, fn x -> x == ["パトカー"] end)      
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(98)> Enum.split_while(pc1, fn x -> x == ["パトカー"] end) 
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(99)> Enum.split_while(pc1, fn x -> x == "パトカー" end)  
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(100)> Enum.split_while(pc1, fn x -> x == "パトカ" end)  
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(101)> Enum.split_while(pc1, fn x -> x == "" end)      
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(102)> Enum.split_while(pc1, fn x -> x ==  end)  
** (SyntaxError) iex:102:37: syntax error before: end. "end" is a reserved word in Elixir and therefore its usage is limited. For instance, it can't be used as a variable or be defined nor invoked as a regular function
     |
 102 | Enum.split_while(pc1, fn x -> x ==  end)
     |                                     ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(102)> Enum.split_while(pc1, fn x -> x == ["パトカー"] end)
{[], ["パ", "ト", "カ", "ー"]}
```

```
iex(103)> Enum.split_while([1, 2, 3, 4], fn x -> x > 0 end)
{[1, 2, 3, 4], []}
```

```
iex(104)> Enum.split_while([1, 2, 3, 4], fn x -> x > 1 end)
{[], [1, 2, 3, 4]}
```

```
iex(105)> Enum.split_while([1, 2, 3, 4], fn x -> x > 2 end)
{[], [1, 2, 3, 4]}
```

```
iex(106)> Enum.split_while([1, 2, 3, 4], fn x -> x > 0 end)
{[1, 2, 3, 4], []}
```

```
iex(107)> Enum.split_while([1, 2, 3, 4], fn x -> x < 3 end)
{[1, 2], [3, 4]}
```


```
iex(108)> Enum.split_while([1, 2, 3, 4], fn x -> x < 3 end)
{[1, 2], [3, 4]}
```

```
iex(109)> 
nil
```

```
iex(110)> 
nil
```

```
iex(111)> Enum.split(pc1, 1)
{["パ"], ["ト", "カ", "ー"]}
```

```
iex(112)>  Enum.with_index(pc1, tx1)
** (FunctionClauseError) no function clause matching in Enum.with_index/2    
    
    The following arguments were given to Enum.with_index/2:
    
        # 1
        ["パ", "ト", "カ", "ー"]
    
        # 2
        ["タ", "ク", "シ", "ー"]
    
    Attempted function clauses (showing 4 out of 4):
    
        def with_index(enumerable, offset) when is_list(enumerable) and is_integer(offset)
        def with_index(enumerable, fun) when is_list(enumerable) and is_function(fun, 2)
        def with_index(enumerable, offset) when is_integer(offset)
        def with_index(enumerable, fun) when is_function(fun, 2)
    
    (elixir 1.15.6) lib/enum.ex:3831: Enum.with_index/2
    iex:112: (file)
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x + y end )
error: undefined function tx1/1 (there is no such import)
  iex:112

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x <> y end )
error: undefined function tx1/1 (there is no such import)
  iex:112

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x ++ y end )
error: undefined function tx1/1 (there is no such import)
  iex:112

** (CompileError) cannot compile code (errors have been logged)
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x[] ++ y[] end )
** (SyntaxError) iex:112:37: syntax error before: ']'
     |
 112 | Enum.zip_with(pc1, tx1 fn x, y -> x[] ++ y[] end )
     |                                     ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x <> y end )    
error: undefined function tx1/1 (there is no such import)
  iex:112

** (CompileError) cannot compile code (errors have been logged)

iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x[] <> y[] end )
** (SyntaxError) iex:112:37: syntax error before: ']'
     |
 112 | Enum.zip_with(pc1, tx1 fn x, y -> x[] <> y[] end )
     |                                     ^
    (iex 1.15.6) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.6) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.6) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```

```
iex(112)> Enum.zip_with(pc1, tx1 fn x, y -> x <> y end) 
error: undefined function tx1/1 (there is no such import)
  iex:112

** (CompileError) cannot compile code (errors have been logged)
```