# Remove Reactive's map from the equation

**URL:** <https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635>\
**Category:** Internals & Design\
**Tags:** question, proposal\
**Created:** [August 30, 2017, 7:42pm UTC](https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635 "2017-08-30T19:42:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 30, 2017, 7:42pm UTC](https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635/1 "2017-08-30T19:42:14Z")

</div>

I find `Reactive.Signal`s extremely useful, especially for GUIs and in combination with `Gtk` à la `GtkReactive`.

To map one signal to another via some function we use `Reactive.map`. I can’t help but think that the resulting code would be much prettier if we didn’t need to use this ‘map’ syntax, but instead used the functions _directly_ on the signals. For example, for `x = Signal(π)`, `y = map(sin, x)` would simply become `y = sin(x)`. Apart from the prettier syntax, I imagine that this could simplify existing functionalities and/or make non-existing ones available.

Is this completely impossible?

---

<div class="post-metadata">

**Author:** ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)\
**Post date:** [August 30, 2017, 8:34pm UTC](https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635/2 "2017-08-30T20:34:57Z")

</div>

I was just thinking about that, I don’t think it is impossible…

I thought of also adding “silent” Signals … Signals that you cannot push into, and they do not update,  
but they remember their inputs and if you derive a map from them it will result in a function of the silent signal inputs  
which is active.  
For example:

```julia
a = Signal(1.0)
b = Signal(10.0)
c = a-b #resulting type is silent signal
d = map(c) do x
    x^2
end

#is equivalent to 
d = map(a,b) do x,y
    (x-y)^2
end

```

Ans also of adding a concept of data\_age per node, that is a counter that increments every time the value of the node changes(actually changes) , this is useful for avoiding re-drawing in GUI for example , and it will allow to turn on and off the drop repeats feature.  
and for a polling design pattern.

And I thought of adding the concept of sink/source and to allow only one sink/source per node … that is a node can only be the result of a single map.  
with this then we can also have pro-active programming where you poll a node and it forces computation all the way to its sources.  
we can still have binding but they will lower precedence when going back in the tree.

And I also thought of making each node remember its world\_age and also the main event loop can remember its world\_age, and whenever an action of a node with newer world\_age shows up in the event loop then simply restart it.  
So once the code finished loading and firing up a few times, the event loop is no longer re-started.

I thought of a lot of things…

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [August 31, 2017, 12:58am UTC](https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635/3 "2017-08-31T00:58:33Z")

</div>

I also agree that it can be done, but it will have some rough edges. I did something like that with [Sims.jl](https://github.com/tshort/Sims.jl). Reactive variables and other symbolic types can combine in expressions. You have to manually define the functions that work with Reactive inputs.

What can be clumsy is that users will probably run into functions where this doesn’t work. My use case is a DSL where the scope is confined a bit, so this clumsiness isn’t too bad.

Another option is to define your own mini DSL with a macro that translates functions to use `map`.

Lastly, there’s been some talk in Base of a more concise syntax for anonymous functions. That would help here.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 31, 2017, 7:56am UTC](https://discourse.julialang.org/t/remove-reactives-map-from-the-equation/5635/4 "2017-08-31T07:56:55Z")

</div>

Cool stuff!
