• Stars
    star
    17
  • Rank 1,257,181 (Top 25 %)
  • Language
    Ada
  • License
    GNU Lesser Genera...
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Ada 2012 implementation of the Rx methodology

[Alire CI Alire indexed LGPL licensed

README

RxAda, an experiment on porting ReactiveX to Ada.

Article at the Journal of Systems Architecture with details about internals and package organization.

Quick example. Suppose a Java 8 case where we print the length of a string:

Observable
   .just("Hello, world!")
   .map(s -> s.length())
   .subscribe(len -> System.out.println(len));

With RxAda this becomes (tested with gnat GPL 2015/2016 and gnat from Ubuntu 16.10):

declare
   S : Rx.Subscriptions.Subscription;
begin
   S := -- We can't ignore the resulting subscription in Ada
     Just ("Hello, world!")
     & Map (Length'Access)
     & Subscribe (Put_Line'Access);

Type checks are performed at compile time.

For a working example check the file rx-examples-basic.adb and the other examples in the src/main folder

For even more exhaustive examples, check the main test suite body: rx-tests.adb

Quick start

You need to instantiate a package for each type you want to use in a Rx chain, and a transformation package for each pair of types involved in some operation. The basic String and Integer types are already available in Rx.Std. Supposing you didn't know about this, you would do:

package Strings  is new Rx.Indefinites (String);  -- Comes pre-instantiated in Rx.Std
package Integers is new Rx.Definites (Integer);   -- Comes pre-instantiated in Rx.Std
package StrToInt is new Rx.Operators (Strings.Observables, Integers.Observables);

Otherwise, it is enough to do:

package StrToInt is new Rx.Operators (Std.Strings, Std.Integers);

Then, you have to "use" them so their "&" function becomes visible. As a side effect, Rx operators become visible too, although they can be prefixed with their package for clarity, if preferred.

Functions are passed to operators via their 'Access, so standard accessibility checks are applied.

Rationale and design goals

I became acquainted with RxJava recently, and soon appreciated its power for tidy code and sane concurrency in event-driven systems (like Android). This is particularly true when using Java 8 with lambda functions.

Given Ada lack of lambda functions and inline generics, increased verbosity is inevitable: functions have to be declared in advance (and at library level), and the types involved require generic instantiations in advance too.

Design goals:

  • Make the user code as tidy and understandable as possible, following the Java 8 example (i.e., avoid RxC++ cryptosyntax).
  • Make defaults as simple as possible for a new user to ease the learning curve.

Some highlights about the library implementation:

  • The library makes extensive use of "signature packages" aka "traits" (thanks go to Emmanuel Briot for his traits-based container library). Check rx-types.ads and rx-operators.ads for examples, and the Rx.Traits.* hierarchy. However, this is mostly hidden from the user. Beginners can use simple instantiations of Rx.Definites or Rx.Indefinites with their types of choice.
  • There is very little explicit dynamic memory management for now in the library code, thanks to Ada use of unconstrained types and the Ada.Containers.Holders 2012 package.

What's next

I intend to continue experimenting with this library, which is providing me lots of fun. I had to make several attempts to arrive at this design, which was not clear in my mind as a goal, so it kind of emerged from the various attempts. In this regard, heartfelt thanks to all contributors from comp.language.ada to the several discussions I started there (e.g., 1, 2).

LICENSE

This project is licensed under LGPL v3.

More Repositories

1

btrfs-status

My personal assessment on btrfs status vs the official one at https://btrfs.wiki.kernel.org/index.php/Status
19
star
2

yeison

A json-like data structure library in Ada
Ada
8
star
3

iterators

Functional iterators for Ada 2012
Ada
6
star
4

sheetmusic

Transcriptions of public domain music using Lilypond and Musescore
LilyPond
5
star
5

alire-old-discussion

Design of an Ada language library repository
5
star
6

ada4cmake

cmake macros for simple gnat project inclusion
CMake
4
star
7

agpl

Ada General Purpose Library -- Miscellaneous utilities
Ada
4
star
8

player-ada

Ada bindings for the player robotic platform
Ada
4
star
9

stopwatch

A type to track elapsed time
Ada
3
star
10

workers

Simple-to-use worker pools for Ada
Ada
3
star
11

adagio

G2 network server leaf
Ada
3
star
12

uri-ada

URI parsing for Ada
Ada
3
star
13

unitest

Test of unicode flags in GNAT
Ada
3
star
14

vnet

High-level virtual network for robotics experimentation
C++
2
star
15

aaa

Alex's Ada Assortment
Ada
2
star
16

optional

Optional types for Ada
Ada
2
star
17

hungarian

Ada wrapper for the fast Stachniss' Hungarian solver
Ada
2
star
18

gnat-gpl-bugs

Test cases for various bugs in the latest GNAT GPL edition, to check their fixing on successive editions
Ada
2
star
19

2022-AEiC-alire-tutorial

Materials for the Alire tutorial at AEiC'22
TeX
2
star
20

mandelbrot_ascii

Mandelbrot renderer in "ASCII" (unicode actually, but text nonetheless)
Ada
2
star
21

umwi

Unicode Monospace Width Information
Ada
1
star
22

den

Directory Enumeration for Ada
Ada
1
star
23

cant-stop-odds

Odds for the Can't stop game
Python
1
star
24

ekfvloc

EKF-based localization library for Gearbox and Player
C++
1
star
25

vmapfile

vmapfile map driver changes to be contributed to player 3 robotic platform
C++
1
star
26

sancta

SANCTA multi-robot task allocation library
Ada
1
star
27

ansi-ada

ANSI control sequences for the Ada language
Ada
1
star
28

utf8test

Test unicode output with `-gnatW8`
Ada
1
star
29

minirest

Minimalist REST Ada client library
Ada
1
star
30

embedded-aws-templates

Ripped out minimal functionality from Ada Web Server and Templates Parser for embedded resources
Ada
1
star
31

Ada_CI_Workflows

Ready-to-use workflows to add Continuous Integration to Ada projects
Ada
1
star
32

skel_ada

Skeleton for Ada projects
1
star
33

ajunitgen

Generator of JUnit-compatible XML reports in Ada
Ada
1
star
34

toml_slicer

TOML file direct manipulation without parsing
Ada
1
star
35

dl-ada

Minimal binding to libdl
Ada
1
star