rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.67k stars 445 forks source link

Pipe placeholder should have precedence over pipe #5377

Open Kingdutch opened 2 years ago

Kingdutch commented 2 years ago

The pipe placeholder is really cool because it allows you to create specialised functions more quickly.

let splitAtSeparator = Js.String2.split(_, ";")

This works great! However, the next step would be to create a processing pipeline using the pipe operator, to compose functions together without having to declare a new function on the ReScript side.

let splitClean = Js.String2.split(_, ";")->Js.Array2.map(Js.String2.trim)

In theory this should work just as well, but unfortunately the compiler starts treating this as a function execution rather than as a composed function and produces the following error:

This expression should not be a function, the expected type is Js.Array2.t<'a>

The above example is a bit contrived, but it can clean up some nested code in case you're piping to things like Belt.Option.mapWithDefault which in turn would do some more nested processing. Coming up with intermediate variable names in those situations can be a chore.

github-actions[bot] commented 17 hours ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.