Reputation: 19
Hi I'am learning elixir atm (just started) and i never used to do functional programming, so my question is what does brackets after function name do. I am watching some internet course, and want to try to make some app for training but dont really understand.
defmodule Cards do
def create_deck do
values = ["Ace","Two","Three", "Four", "Five"]
suits = ["Spades", "Clubs", "Hearts", "Diamonds"]
for suit <- suits, value <- values do
"#{value} of #{suit}"
end
end
def shuffle(deck) do
Enum.shuffle(deck)
end
def contains**(deck, card) do
Enum.member?(deck, card)
end
def deal(deck, hand_size) do
Enum.split(deck, hand_size)
end
def save(deck, filename) do
binary = :erlang.term_to_binary(deck)
File.write(filename, binary)
end
def load(filename) do
{status, binary} = File.read(filename)
:erlang.binary_to_term(binary)
end
end
Upvotes: 0
Views: 399
Reputation: 15293
The syntax (deck)
is a way of specifying the argument to the function. deck
is the argument passed to the shuffle
function. You can find a bit more about the function syntax here.
Upvotes: 1