Skip to content
Browse files

[feature] stdlib/session: non-blocking versions of combinators

  • Loading branch information...
1 parent 59bd529 commit d7a3b3fc4874cfa7b3ab1d57460ad8859c2d1bb6 François-Régis Sinot committed
Showing with 18 additions and 0 deletions.
  1. +18 −0 stdlib/core/rpc/core/session.opa
View
18 stdlib/core/rpc/core/session.opa
@@ -639,6 +639,24 @@ Session = {{
on_message_basic(_ : void, msg : 'message) = on_message(msg) : Session.basic_instruction
make_generic_default(void, { concurrent = on_message_basic })
+ /**
+ * Concurrent version of the [map] combinator.
+ */
+ map(f:'b -> 'a, channel:channel('a)) =
+ make_callback(x -> send(channel, f(x))) : channel('b)
+
+ /**
+ * Concurrent version of the [filter] combinator.
+ */
+ filter(f:'a -> bool, channel: channel('a)) : channel('a) =
+ make_callback(message -> if f(message) then send(channel, message))
+
+ /**
+ * Concurrent version of the [filter_map] combinator.
+ */
+ filter_map(f:'a -> option('b), channel:channel('b)) : channel('a) =
+ make_callback(message -> Option.iter(send(channel, _), f(message)))
+
}}

0 comments on commit d7a3b3f

Please sign in to comment.
Something went wrong with that request. Please try again.