Default argument which is the 1st one and not the only one. How?

In a third-party project, in the models, I’ve encountered functions like this:


<span style="color:#323232;">  def changeset(model \ %__MODULE__{}, params) do
</span><span style="color:#323232;">    model
</span><span style="color:#323232;">    |> cast(params, @required_fields ++ @optional_fields)
</span><span style="color:#323232;">    |> validate_required(@required_fields)
</span><span style="color:#323232;">  end
</span><span style="color:#323232;">
</span>

How can a function have a default argument which is both a) first and b) followed by a mandatory one?

What’s interesting, they work properly.

stifle867,

That’s interesting. What if you were to call it with only 1 argument? Would that not match, or would it match as the 1st argument is using the default?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • elixir@programming.dev
  • DreamBathrooms
  • everett
  • osvaldo12
  • magazineikmin
  • thenastyranch
  • rosin
  • normalnudes
  • Youngstown
  • Durango
  • slotface
  • ngwrru68w68
  • kavyap
  • mdbf
  • InstantRegret
  • JUstTest
  • ethstaker
  • GTA5RPClips
  • tacticalgear
  • Leos
  • anitta
  • modclub
  • khanakhh
  • cubers
  • cisconetworking
  • megavids
  • provamag3
  • tester
  • lostlight
  • All magazines