Safe Haskell | Safe-Inferred |
---|
A Stream is a collection of LEvent.LEvent
s which is hopefully sorted in
time order.
Synopsis
- data Stream a
- empty :: Stream a
- from_logs :: [Log.Msg] -> Stream a
- from_event_logs :: a -> [Log.Msg] -> Stream a
- from_events :: [a] -> Stream a
- from_sorted_list :: [LEvent.LEvent a] -> Stream a
- from_event :: a -> Stream a
- from_sorted_events :: [a] -> Stream a
- to_list :: Stream a -> [LEvent.LEvent a]
- write_logs :: Log.LogMonad m => Stream a -> m [a]
- partition :: Stream a -> ([a], [Log.Msg])
- logs_of :: Stream a -> [Log.Msg]
- events_of :: Stream a -> [a]
- length :: Stream a -> Int
- take_while :: (a -> Bool) -> Stream a -> Stream a
- drop_while :: (a -> Bool) -> Stream a -> Stream a
- cat_maybes :: Stream (Maybe a) -> Stream a
- sort :: Stream Score.Event -> Stream Score.Event
- merge_asc_lists :: [Stream Score.Event] -> Stream Score.Event
- merge_log :: Log.Msg -> Stream a -> Stream a
- merge_logs :: [Log.Msg] -> Stream e -> Stream e
- levent_key :: LEvent.LEvent Score.Event -> RealTime
- first :: (a -> Bool) -> (a -> a) -> Stream a -> Stream a
- first_last :: (a -> Bool) -> (a -> a) -> (a -> a) -> Stream a -> Stream a
- zip :: [a] -> Stream x -> Stream (a, x)
- zip_on :: ([a] -> [b]) -> Stream a -> Stream (b, a)
- zip3 :: [a] -> [b] -> Stream x -> Stream (a, b, x)
- zip3_on :: ([a] -> [b]) -> ([a] -> [c]) -> Stream a -> Stream (b, c, a)
- zip4 :: [a] -> [b] -> [c] -> Stream x -> Stream (a, b, c, x)
- pretty_short_events :: Stream Score.Event -> Text
- short_events :: Stream Score.Event -> [Text]
Documentation
A list seems inefficient, since each call appends to the stream. A block call will then append a bunch of events which need to be copied, and recopied as part of the larger chunk for the next block call up. It's possible the head of the stream will also be copied every time something is appended to it, but I'm not sure about that. It could also be that the number of events is low enough that all the inefficiency doesnt actually matter, but I'm not sure. I need to understand profiling to tell.
TODO one possibility is a MergeList:
data MergeList a = Chunk [a] | Merge (MergeList a) (MergeList a)
This way I don't need to copy large chunks multiple times. Also, if I make sure there is no data dependency between the merge branches, I can evaluate them in parallel.
Each call generates a chunk [Event], and the chunks are then joined with (<>). This means every cons is copied once, but I think this is hard to avoid if I want to merge streams.
TODO the Functor and Traversable can destroy the order, but this isn't checked. Maybe I shouldn't have them?
Currently I don't actually track order, and just trust the callers.
Instances
construct
from_event_logs :: a -> [Log.Msg] -> Stream a Source #
from_events :: [a] -> Stream a Source #
from_sorted_list :: [LEvent.LEvent a] -> Stream a Source #
from_event :: a -> Stream a Source #
from_sorted_events :: [a] -> Stream a Source #
Promise that the stream is really sorted.
extract
to_list :: Stream a -> [LEvent.LEvent a] Source #
write_logs :: Log.LogMonad m => Stream a -> m [a] Source #
transform
sort :: Stream Score.Event -> Stream Score.Event Source #
merge_asc_lists :: [Stream Score.Event] -> Stream Score.Event Source #
Merge sorted lists of events. If the lists themselves are also sorted, I can produce output without scanning the entire input list, so this should be more efficient for a large input list than (<>).
This assumes all the streams are sorted. I could check first, but this would destroy the laziness. Instead, let it be out of order, and Convert will complain about it.
levent_key :: LEvent.LEvent Score.Event -> RealTime Source #
This will make logs always merge ahead of score events, but that should be ok.
specific transformations
first :: (a -> Bool) -> (a -> a) -> Stream a -> Stream a Source #
Apply to the first Event that matches the predicate.
first_last :: (a -> Bool) -> (a -> a) -> (a -> a) -> Stream a -> Stream a Source #
Apply to the first and last Event that matches the predicate. If there are fewer than 2 such events, do nothing.
zip
misc util
pretty_short_events :: Stream Score.Event -> Text Source #
Like Score.short_events
, but works on a Stream.
short_events :: Stream Score.Event -> [Text] Source #