You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't understand this code for set default function in Elixir
defmoduleSample.Default.Paramsdodeffirst(list,val\\nil)deffirst([head|_],_),do: headdeffirst([],val),do: valend# defmodule Sample.Default.Params do# def first(list, val \\ nil), do: val # Why we remove this one?# def first([head | _], _), do: head# def first([], val), do: val# end# The warnning message# warning: this clause for first/2 cannot match because a previous clause at line 2 always matches# sample_default_params.exs:3# warning: this clause for first/2 cannot match because a previous clause at line 2 always matches# sample_default_params.exs:4# Test cases# Sample.Enum.first([1,2,3]) # => 1# Sample.Enum.first([], 1) # => 1# Sample.Enum.first([]) # => nil# Sample.Enum.first([1,2,3], 0) # => 1
Solution:
Lesson:
The text was updated successfully, but these errors were encountered:
Problem:
I don't understand this code for set default function in Elixir
Solution:
Lesson:
The text was updated successfully, but these errors were encountered: