Chain JS calls in interop

Hello,
I know it is possible to chain props access in bucklescript, but I am not sure if it is possible to write bindings that call chained functions.
I know that you can define externals with bs.send and then they will be compiled to just chained calls, but If I want to build a helper function that is just several external calls chained it will be compiled to an actual function instead of a zero cost call.
To put an example, this is what I have:

external getDataRange : sheet -> range = "getDataRange"  [@@bs.send]    
external getValues : range -> Cell.t array array = "getValues"  [@@bs.send]
let getAllValues sheet =  getDataRange sheet |. getValues

But this is what I wanted:

external getDataRange : sheet -> range = "getDataRange"  [@@bs.send]    
external getValues : range -> Cell.t array array = "getValues"  [@@bs.send]
external getAllValues : sheet -> Cell.t array array = "getDataRange().getValues"  [@@bs.send]

But the above produces wrong JS code. If this even possible?

Not really possible.

IMO zero cost is best for the direct access it supports only. If this is something you’re likely to use often, a helper function is arguably better because it’ll result in less bundle size than if the chained calls were inlined all the time.

2 Likes