Skip to content

Instantly share code, notes, and snippets.

@MonkeyIsNull
Created November 3, 2015 21:25
Show Gist options
  • Save MonkeyIsNull/8b26a6a05ba0d54b13cf to your computer and use it in GitHub Desktop.
Save MonkeyIsNull/8b26a6a05ba0d54b13cf to your computer and use it in GitHub Desktop.
defmodule Dt do
# Create a list with six star wars characters
swc = ["c3po", "r2d2", "bb8", "han", "luke", "leia"]
# Get the third item out of the list
IO.puts "3rd => " <> Enum.at(swc,2)
# Create another list with three characters
bad_guys = [:boba_fett, :vader, {:jabba, :hutt}]
# Create a third list that contains both previous lists
all = swc ++ bad_guys
# can't use IO.puts here
IO.inspect all
# delete the 7th
IO.inspect List.delete_at(all, 6)
# add one more
[ :yoda | all ]
# use in to check that someone exists
IO.puts "Is Jabba there? => #{ {:jabba, :hutt} in all }"
c = %{ :name => "Luke Skywalker", :side => :rebel}
IO.puts "Name: #{c[:name]} fights for the #{c[:side]} alliance"
# we could just re-bind c as well
c_updated = Map.put(c, :weight, 150)
# lom
lom = [c, %{:name => "r2d2", :side => :rebel},
%{:name => "IG-88", :side => :imperial}]
IO.inspect lom
# lom update
IO.inspect List.replace_at(lom, 1, %{ :name => "Jabba the Hut", :side => :scum })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment