defmodule SingleDep do require Integer require Logger use Reactivity @moduledoc """ SingleDep shows how to use Reactivity with a single dependency. We initialize the system by creating two source signals. These signals take in: - A function that takes one parameter (it's previous value). - An initial value. - An rate of value generation (ms). - A name. We create temperature and seconds. In the app() function we create a new signal "hot_cold" that will produce a pepper emoji or a snowflake emoji based on the temperature. Then we apply a new function to that that prints out the current value. Finally we create a """ def hot_cold(t) do if t > 300 do :"🌶️" else :"❄️" end end def app do # Create a new signal :hotcold based on the source :temperature. source(:temperature) |> liftapp(&hot_cold/1) |> register(:hotcold) # Map a print function on the hotcold signal. source(:hotcold) |> liftapp(fn(x) -> IO.puts x end) # # Create a new signal :kelvin based on the source :temperature source(:temperature) |> liftapp(&(&1 + 237.15)) |> register(:kelvin) |> liftapp(&(IO.puts &1)) end end