Suggestion for binding Rx.js `bindNodeCallback` function?



I am in the middle of writing Reason bindings for Rxjs library. I have been able to write bindings for many functions and operators. However, bindNodeCallback is a bit tricky to handle. Here is my current implementation:

(* *)
type 'a nodeCallback = Js.Exn.t Js.nullable -> 'a Js.nullable -> unit [@bs]

external bindNodeCallback1 : ('a -> 'b nodeCallback -> unit [@bs.uncurry]) -> ('a -> 'b observable [@bs])
= "bindNodeCallback" [@@bs.module "rxjs"]

external bindNodeCallback2 : ('a -> 'b -> 'c nodeCallback -> unit [@bs.uncurry]) -> ('a -> 'b -> 'c observable [@bs])
= "bindNodeCallback" [@@bs.module "rxjs"]

This is how it can be used:

external readFile : string -> string nodeCallback -> unit = "readFile" [@@bs.module "fs"]
external readFile2 : string -> string -> string nodeCallback -> unit = "readFile" [@@bs.module "fs"]

let bnc1 : (string -> string observable [@bs]) = bindNodeCallback1(readFile)
let bnc2 : (string -> string -> string observable [@bs]) = bindNodeCallback2(readFile2)

let z1 = bnc1 "/home/harshal/ub/bs-marble/" [@bs]
let z2 = bnc2 "/home/harshal/ub/bs-marble/" "utf-8" [@bs]

let _ = subscribe z1 (fun y -> Js.log y)
let _ = subscribe z2 (fun y -> Js.log y)

I am not sure if this is the most optimal way of doing it. Any suggestions?

Note: Currying is not possible as the function returned by bindNodeCallback has a length of zero. It is using arguments list to handle variadic type.