Skip to content

Commit

Permalink
lift now supports do notation but breaks prev. API. closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi committed Jun 12, 2014
1 parent 85a9355 commit a6bd393
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/React.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import Base: push!, reduce, merge, map,
# A signal is a value that can change over time.
abstract Signal{T}

typealias Time Float64

# A topological order
begin
local counter = uint(1)
Expand Down Expand Up @@ -208,11 +206,11 @@ function push!{T}(inp :: Input{T}, val :: T)
end
push!{T}(inp :: Input{T}, val) = push!(inp, convert(T, val))

lift(output_type::Type, f :: Function, inputs :: Signal...) =
lift(f :: Function, output_type :: Type, inputs :: Signal...) =
Lift{output_type}(f, inputs...)

lift(f :: Function, inputs :: Signal...) =
lift(Any, f, inputs...)
lift(f, Any, inputs...)

sampleon{T, U}(s1 :: Signal{T}, s2 :: Signal{U}) = SampleOn{T, U}(s1, s2)
filter{T}(pred :: Function, v0 :: T, s :: Signal{T}) = Filter{T}(pred, v0, s)
Expand All @@ -225,7 +223,7 @@ function reduce{T, U}(f :: Function, v0 :: T, signal :: Signal{U})
function foldp(b)
a = f(a, b)
end
lift(T, foldp, signal)
lift(foldp, T, signal)
end

#############################################
Expand Down
4 changes: 2 additions & 2 deletions tests/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ number() = int(rand()*1000)
## Basics

a = Input(number())
b = lift(Int, x -> x*x, a)
b = lift(x -> x*x, Int, a)

# type conversion
push!(a, 1.0)
Expand All @@ -20,7 +20,7 @@ push!(a, -number())
@test b.value == a.value*a.value

## Multiple inputs to Lift
c = lift(Int, +, a, b)
c = lift(+, Int, a, b)
@test c.value == a.value + b.value

push!(a, number())
Expand Down
6 changes: 3 additions & 3 deletions tests/call_count.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ number() = int(rand()*100)
a = Input(0)
b = Input(0)

c = lift(Int, +, a, b)
c = lift(+, Int, a, b)
d = merge(a, b)
e = lift(Int, +, a, lift(Int, x->2x, a)) # Both depend on a
f = lift(Int, +, a, b, c, e)
e = lift(+, Int, a, lift(x->2x, Int, a)) # Both depend on a
f = lift(+, Int, a, b, c, e)

count = s -> reduce((x, y) -> x+1, 0, s)

Expand Down

0 comments on commit a6bd393

Please sign in to comment.