What does this operator (>>=) mean?


#1

I have meet some code about GraphQL.
Could you tell me what is this operator : >>= ?
Where can I find the document of this operator?
Thank you!

 let execute_request = (ctx, schema, _req, body) =>
   Cohttp_lwt.Body.to_string(body)
   >>= (
     body' => {
 .....
 }
 )

#2

There is a similar question here:

you can find answer in this documentation:
https://mirage.io/wiki/tutorial-lwt

is bind operator with this signature:
val ( >>= ): 'a Lwt.t -> ('a -> 'b Lwt.t) -> 'b Lwt.t


#3

And just in case, bind goes by the name of flatMap in a lot of libraries, including Belt.


#4

Note that different modules can redefine the same operator and many do. In this specific case it’s coming from this module: https://ocsigen.org/lwt/5.1.0/api/Lwt.Infix

The Lwt docs actually recommend to use their PPX (syntax extension) instead of operators so dealing with promises looks more like async/await syntax in JavaScript. So your above example would become:

let execute_request = (ctx, schema, _req, body) => {
  let%lwt body = Cohttp_lwt.Body.to_string(body);
  ...
};