.net - Convert IObservable<Timestamped<T>> to IObservable<TimeInterval<T>> -


how can convert observable sequence of timestamped<t> sequence of timeinterval<t>where interval time between timestamps on original sequence?

given input sequence..

new timestamped<int>(1, datetime.parse("2000-01-01 00:00:01")) new timestamped<int>(2, datetime.parse("2000-01-01 00:00:05")) new timestamped<int>(3, datetime.parse("2000-01-01 00:01:04")) 

.. output be:

new timeinterval<int>(1, timespan.parse("00:00:00")) new timeinterval<int>(2, timespan.parse("00:00:04")) new timeinterval<int>(3, timespan.parse("00:00:59")) 

i think it.

var s = source.publish().refcount(); var sprev = s.take(1).concat(s); var scurrent = s;  var converted = observable.zip(sprev, scurrent, (prev, current) =>    new timeinterval<int>(current.value, current.timestamp - prev.timestamp)); 

the thing i'm not sure of if zip ends when either sequence ends. assume does, i've not tested it.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -