Skip to content

put function argument last in higher order functions #31

@rogpeppe

Description

@rogpeppe

When writing deriveFmap or deriveFilter, it's often nice to write
the predicate function inline. Since that can often take
multiple arguments, the code reads more nicely when
the function comes second and the slice comes first,
so it's clear at first glace what slice is being operated on
before starting to read the function itself.

For example:

 items := deriveFmap(otherItems, func(i OtherItem) Item {
      return OtherItem{
          Foo: i.Foo,
          Bar: i.Bar,
      }
 })

rather than:

 items := deriveFmap(func(i OtherItem) Item {
      return OtherItem{
          Foo: i.Foo,
          Bar: i.Bar,
      }
 }, otherItems), 

Alternatively, the goderive code could allow both forms and generate the
expected function signature based on the argument types that are passed
in.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions