witchcrafters/algae

Constructor should take 1 argument

OvermindDL1 opened this issue · 2 comments

The constructor function of new should probably only take a single value, a keyword list of what to set on the map with it defaulting to just [], then the new would just be new/1 without other arguments, thus making piping easier and do not need to specify earlier fields to set later ones.

What about currying the new constructor? I am still learning, but isn't this how it is in PureScript, Haskell, etc.? More in #37 (comment) but basically:

iex(4)> Person.new
#Function<1.23432587/1 in Person.new/0>

iex(5)> Person.new.("lofa")
#Function<4.23432587/1 in Person."new (overridable 1)"/1>

iex(6)> Person.new.("lofa").(27)
%Person{age: 27, name: "lofa"}

iex(7)> Person.new("lofa").(27)
%Person{age: 27, name: "lofa"}

a keyword list of what to set on the map with it defaulting to just [],

I disagree. Now you have multiple input syntaxes, sometimes a keyword list is a single input, sometimes it's multiple. You can get the same functionality by using the normal struct sugar.

What about currying the new constructor?

As much as I'd like Elixir to be auto-curried, it does impose some overhead that we may not want by default. It's also a big surprise to folks only using Algae as a convenient struct DSL. I'm not against having a separate curried constructor, however 🤔 Would be trivial via Quark.