rxada_0.1.1_dd9da799/src/priv/rx-impl-events.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
with Ada.Exceptions;

with Rx.Errors;
with Rx.Impl.Typed;

generic
   with package Typed is new Rx.Impl.Typed (<>);
package Rx.Impl.Events is

   type Kinds is (On_Next, On_Complete , On_Error);

   type Event (Kind : Kinds) is private;

   function On_Next (V : Typed.T) return Event;

   function On_Complete  return Event;

   function On_Error (E : Errors.Occurrence) return Event;

   function On_Error (E : Ada.Exceptions.Exception_Occurrence) return Event;

   function Value (E : Event) return Typed.T
     with Pre => E.Kind = On_Next;

   function Error (E : Event) return Errors.Occurrence
     with Pre => E.Kind = On_Error;

private

   type Event (Kind : Kinds) is record
      case Kind is
         when On_Next      => V : Typed.D;
         when On_Error     => E : Errors.Occurrence;
         when On_Complete  => null;
      end case;
   end record;

   use Typed.Conversions;

   function On_Next (V : Typed.T) return Event is (On_Next, +V);

   function On_Complete  return Event is (Kind => On_Complete );

   function On_Error (E : Errors.Occurrence) return Event is (On_Error, E);

   function On_Error (E : Ada.Exceptions.Exception_Occurrence) return Event is (On_Error, Errors.Create (E));

   function Value (E : Event) return Typed.T is (+E.V);

   function Error (E : Event) return Errors.Occurrence is (E.E);

end Rx.Impl.Events;