Note that there are some explanatory texts on larger screens.

plurals
  1. POScala Advanced Type Usage
    primarykey
    data
    text
    <h2>The Background</h2> <p>I'm working on an event library in Scala. <a href="https://github.com/goldmar/CEScala/" rel="nofollow noreferrer">In my library</a> you can define events like this:</p> <pre><code>val e1 = new ImperativeEvent[Int] </code></pre> <p>You can trigger them like this:</p> <pre><code>e1(42) </code></pre> <p>You can create reactions like this:</p> <pre><code>val r1 = (i: Int) =&gt; println(i) </code></pre> <p>And attach them to the event like this:</p> <pre><code>e1 += r1 </code></pre> <p>There is also some other stuff (like event transformations, compositions etc). I use the <a href="http://esper.codehaus.org/" rel="nofollow noreferrer">Esper CEP engine</a> as the backend of my library. Esper uses an SQL-like language called EPL for most operations.</p> <h2>The Problem</h2> <p>I'm trying to implement some more advanced concepts like event joins. So now you can define events with multiple properties like this (using tuple types):</p> <pre><code>val e2 = new ImperativeEvent[(Int, String)] </code></pre> <p>And then join them like this:</p> <pre><code>val e3 = e1 join e2 windowLength (30) on "E1.P1 = E2.P1" </code></pre> <p>which performs a join of e1 and e2 on the last 30 occurrances of both on the condition that their respective first properties are equal.</p> <p>This is alright but I'd like to get rid of the strings in my implementation to make the event expressions type checkable. I'd like to change the join expression to something like this:</p> <pre><code>val e3 = e1 join e2 windowLength (30) on e1._1 === e2._1 </code></pre> <p>similar to the way it is done in eg. <a href="http://squeryl.org/" rel="nofollow noreferrer">Squeryl</a>. The problem with this is, I can't access the types of the elements of the tuple type...</p> <h2>The Question</h2> <p>How can I access the tuple types statically? Right now I've only managed to access them at run-time through reflection which does not help me. I'm pretty sure that what I want to achieve is not possible with tuples but I'm wondering if using HLists from the shapeless library or something similar might help in achieving my goal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload