Hopefully you can help me out with this.

I left out function implementations that we should't need to see.  This 
part of the code I think seems ok:


abstract Intervalizer{Time <: Integer, Value <: Union{AbstractFloat, Integer
}}


type StreamingIntervalizer{Time, Value} <: Intervalizer{Time, Value}

  intervalState::IntervalState
  currentValue::Value
  defaultValue::Value

  function StreamingIntervalizer(interval, startTime)

    this = new(IntervalState{Time}(interval, startTime + interval))

    this.defaultValue = zero(Value) # Create a zero of the ::Value.
    this.currentValue = this.defaultValue # Set current value to default.

    return this
  end
end


function intervalize{T, V}(i::Intervalizer{T,V}, time::T, value::V, 
onCompletedInterval)

    if(isNextInterval(i.intervalState, time))

      onCompletedInterval(getCurrentIntervalTime(i.intervalState), i.
currentValue)

      # Set next interval.
      shiftInterval!(i)

      # Reset Value.
      resetValue!(i)

    end

    # Increment current value.
    incrementCurrentValue!(value)
end

I need to inject onCompletedInterval rather than return either something or 
nothing because I don't want to do another if block later to check whether 
a value exists.  I think this is correct, but might be part of the problem.

This is where the issue comes in:

type HistoricalIntervalizer{Time, Value} <: Intervalizer{Time, Value}

  si::StreamingIntervalizer{Time, Value}
  array::Array{Value}

  function HistoricalIntervalizer(interval, startTime)

    array = zeros(Value, 24 * 60)

    this = new(StreamingIntervalizer(interval, startTime), array)

    return this
  end
end


using FastAnonymous

# !! We are stuck having to specify type here, bc saveToArray requires an 
initial array.
array = zeros(Float64, 24 * 60)

# Define our anon function once.
saveToArray = @anon (time, value) -> begin
  array[time + 1] = value
end

function intervalize{T, V}(hi::HistoricalIntervalizer{T,V}, time::T, value::
V)
  saveToArray.array = hi.array
  intervalize(hi.si, time, value, saveToArray)
end
 

With this we have to fix the type of array so we can define the anon 
function.

We could slightly modify this approach by moving the anon function decl 
into the inner constructer so the type is not a problem, but now we will be 
creating multiple anon functions.

Any ideas?

Reply via email to