Skip to content

Indentation of curried functions #957

Open
@ghivert

Description

@ghivert

Hi !

I really like the formatter, but there’s some cases where I wonder if it’s by design or not.
I wonder mainly about curried functions. I’m coming mainly from functional programming (Haskell and stuff) and it’s usual to have something like this:

// In JavaScript for example
const fun = arg1 => arg2 => arg3 => {
  // body...
}
// In Dart for example
fun(arg1) => (arg2) => (arg3) {
  // body...
};

But when doing the latter, it’s indented like this:

fun(arg1) => (arg2) => (arg3) {
    final var = 1;
    return var;
  };

It feels like there’s two unneeded spaces in the function body. With indent guides and other stuff, it renders strangely. Is it on purpose or because of some rules on closures? I know we can do it differently, like:

fun(arg1, arg2, arg3) {}
// And then use a closure at the appropriate place
onEvent: (event) => fun('fromScope', 'alsoFromScope', event);

// Instead of:

fun(arg1, arg2) => (arg3) {};
// And then
onEvent: fun('fromScope', 'alsoFromScope');

It’s a similar result in the end, but it’s a slightly different code.
What do you think about this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions