From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8FEJlOk019959 for ; Thu, 15 Sep 2011 16:19:47 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhYCAA8Jck7Y5v4vmWdsb2JhbABDhFWTFoErjjcUAQEBAQEGDQsHFCaBewEFUSkMAwUDEwoDCwMCAQIBPxkIAQGee41bAYlRiBOBKYQ3gRQEh22LWoUcH4t+ X-IronPort-AV: E=Sophos;i="4.68,387,1312149600"; d="scan'208";a="109215216" Received: from unknown (HELO amout07.alpha-mail.net) ([216.230.254.47]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Sep 2011 16:19:43 +0200 Received: from webarc05.alpha-mail.jp (webarc05 [216.230.254.85]) by amout07.alpha-mail.net with ESMTP id p8FEJb6Q017052; Thu, 15 Sep 2011 23:19:37 +0900 X-Virus-Scanned: amavisd-new at Alpha-Mail Out Received: from ltsub01.alpha-mail.net (ltsub01 [216.230.254.29]) by webarc05.alpha-mail.jp (Postfix) with ESMTP id 31EE814C800F; Thu, 15 Sep 2011 23:19:32 +0900 (JST) Received: from [192.168.0.103] (196.62.205.61.west.global.alpha-net.ne.jp [61.205.62.196]) by ltsub01.alpha-mail.net (Alpha-mail) with ESMTP id 6A4113B8099; Thu, 15 Sep 2011 23:19:36 +0900 (JST) Message-ID: <4E72096C.1040904@itpl.co.jp> Date: Thu, 15 Sep 2011 23:19:24 +0900 From: Satoshi Ogasawara User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: [Caml-list] a push style event combinator Hello, I'd like to announce the release of PEC, a push style event combinator. PEC : https://github.com/osiire/Pec This small module(about 350 LOC) provides - a composable event. - map, choose, never, join and several useful functions. - immediate reactions corresponds sending data to events. - no memory leaks. I think PEC is useful to write event driven systems. The signature is as follows. type 'a event (** [make ()] makes a new event and sender function.*) val make : unit -> 'a event * ('a -> unit) val map : ('a -> 'b) -> 'a event -> 'b event (** [choose l] is a event which will be raised when one of specified events occurred. *) val choose : 'a event list -> 'a event val never : 'a event (** [join ee] is a event which will be raised when a inner event occurred. "Inner event" is a event comes from outer event [ee]. *) val join : 'a event event -> 'a event (** [bind e f] is [join (map f e)] *) val bind : 'a event -> ('a -> 'b event) -> 'b event val scan : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a event val filter : ('a -> bool) -> 'a event -> 'a event val filter_map : ('a -> 'b option) -> 'a event -> 'b event val zip : 'a event -> 'b event -> ('a * 'b) event val take_while : ('a -> bool) -> 'a event -> 'a event val take_while_in : ('a -> bool) -> 'a event -> 'a event val take_n : int -> 'a event -> 'a event val once : 'a event -> 'a event val drop_while : ('a -> bool) -> 'a event -> 'a event val drop_n : int -> 'a event -> 'a event val delay : int -> 'a event -> 'a event val pairwise : 'a event -> ('a * 'a) event (** [subscribe f e] attaches the [f] to the specified event. The [f] will be called when the [e] will occurred. *) val subscribe : ('a -> unit) -> 'a event -> unit (** [value e] returns a reference cell which store a latest value *) val value : 'a -> 'a event -> 'a ref (** [run ()] runs PEC event system and returns a number of queuing size of sended data. *) val run : unit -> int e.g. Using PEC, you can write a drag event from mouse events like this. let (+>) f g = g f (* E is PEC module *) let dragging mouse_down mouse_up mouse_move = E.bind mouse_down (fun dloc -> E.choose [ E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up; E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move; ] +> E.take_while_in (function `Drop _ -> false | _ -> true)) Regards, ogasawara