Elixirの Keyword Lists と Map

  • 0
    Like
  • 0
    Comment
    More than 1 year has passed since last update.

    似ているので覚え書き。

    List

    iex(1)> list1 = [name: "taji", age: 43, address: "Tokyo"]
    [name: "taji", age: 43, address: "Tokyo"]
    
    iex(2)> list1[:address]
    "Tokyo"
    
    iex(3)> list2 = [{:name, "taji"}, {:age, 43}, {:address, "Tokyo"}]  
    [name: "taji", age: 43, address: "Tokyo"]
    
    iex(4)> list2[:address]
    "Tokyo"
    

    Map

    iex(1)> map = %{"name" => "taji", "age" => 43, "address" => "Tokyo"}
    %{"address" => "Tokyo", "age" => 43, "name" => "taji"}
    
    iex(2)> map["address"]
    "Tokyo"