I believe it would make sense to follow the general convention from the
Kernel Access functions and have a Kernel.put_if to place a new value
or override an existing one and a Kernel.update_if to update an
existing value with an anonymous function.
run_if to me seems too general. When reading 'put_if' or 'update_if', I
can immediately determine the intent. With 'run_if', determining the
intent requires further reading.
As far as the naming of maybe_put versus put_if is concerned, the
'maybe' version harkens to Haskell's maybe. The functionality discussed
here is not a direct analogue, though similar.
Just my two cents.
On Mon, 2020-06-08 at 13:51 +0200, José Valim wrote:
> I would like to avoid the maybe_ prefixes. In my mind, I would use
> "maybe_ " for returning {:ok, ...} | {:error, _} or similar.
>
> Furthermore, although we may use maybe_ internally, we don't use the
> maybe_ prefix in any of the public functions. So I would be very
> careful before setting a new naming convention, as establishing the
> wrong convention can be harmful in the long term. The other
> suggestions, run_if/update_if sound more plausible in my opinion.
>
> On Mon, Jun 8, 2020 at 1:29 PM Bruce Tate <[email protected]> wrote:
> > Map.maybe_put then... that works well for me.
> >
> > I love the way maybe_ style functions compose. It makes a
> > tremendous difference to the end product.
> >
> > -bt
> >
> > On Mon, Jun 8, 2020 at 5:20 AM Riccardo Binetti <[email protected]>
> > wrote:
> > > If we also want to have a function in the Map module I think that
> > > the verb should be put, not update (since the operation described
> > > in my first post is effectively a put operation), so eitherx
> > > put_if or maybe_put.
> > >
> > > Regarding the proposed Kernel macro, it seems to me that it can
> > > be used in a more general sense and not only for updating
> > > collections (the first argument can effectively be anything), so
> > > I like the run verb. It could also be apply_if.
> > >
> > > In both cases I personally I find the _if suffix more expressive
> > > than the maybe_ prefix, in my opinion this
> > >
> > > |> run_if(x == 1, some_fun)
> > >
> > > reads more naturally and better conveys the role of the arguments
> > > than
> > >
> > > |> maybe_run(x == 1, some_fun)
> > >
> > > --
> > > Riccardo
> > >
> > > On Monday, June 8, 2020 at 2:57:32 AM UTC+2, Bruce Tate wrote:
> > > > I like the idea as well. And I like the name maybe_update.
> > > >
> > > > -bt
> > >
> > > --
> > > You received this message because you are subscribed to the
> > > Google Groups "elixir-lang-core" group.
> > > To unsubscribe from this group and stop receiving emails from it,
> > > send an email to [email protected].
> > > To view this discussion on the web visit
> > > https://groups.google.com/d/msgid/elixir-lang-core/12633886-f5ce-4b9f-b27c-b0871b472554o%40googlegroups.com
> > > .
> >
> >
> > --
> >
> > Regards,
> > Bruce Tate
> > CEO
> >
> >
> >
> > Groxio, LLC.
> > 512.799.9366
> > [email protected]
> > grox.io
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/c504114a16441f8fe57d1baedf4630fe8f64eb25.camel%40gmail.com.