- 
                Notifications
    
You must be signed in to change notification settings  - Fork 36
 
feat(core): Add runStream as function from of stream.run #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 
           I like stream last approach, in a similar to data last... given you can make a simple sink and have a defaultScheduler but not yet know what the stream is going to be entirely. If that makes any sense 😄  | 
    
| 
           Ok, I found a coherent argument ordering for runStream and runStreamWithLocalTime (newly renamed from runWithLocalTime) that I think makes sense. I'm not really happy with the name runStreamWithLocalTime, though. It'd be nice to find something shorter and at least as clear. Ideas? I'm inclined to keep runEffects' current "flipped" argument order (i.e. scheduler last,   | 
    
| 
           why not just leave it   | 
    
| 
           My thinking is that the name  The "WithLocalTime" suffix, while very explicit, seems a bit wordy. I wonder if there's a way to say the same thing in less than 3 camel humps, like maybe "WithOrigin" or just "At": runWithOrigin, runAt, or runStreamWithOrigin, runStreamAt. Or maybe "Relative": runRelative or runStreamRelative. Do any of those seem appealing or give you other ideas? I'm not totally against runWithLocalTime or runStreamWithLocalTime since they will tend to be used less often than runEffects, but if we could find something more concise, that'd be great.  | 
    
| 
           I like run because like you mention types and the fact this is a stream library but maybe that's me with that said I like runWithOrigin or runWithTime if you really want make it obvious .. though for some reason it almost makes sense to make it runWithEffects ? Thoughts ?  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar/spelling errors only
        
          
                packages/core/src/runStream.js
              
                Outdated
          
        
      | // Run a stream with its own localized clock | ||
| // This transforms time from the provided scheduler's clock to a stream-local | ||
| // clock (which starts at 0), and then *back* to the scheduler's clock before | ||
| // propagating events to sink. IOW, stream.run will see local times, and sink | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"IOW" is slang for in other words. Google sees it as Isle of Wright. Wikipedia lists:
- Isle of Wight (frequently as IoW)
 - The German abbreviation for the Leibniz Institute for Baltic Sea Research
 - ISO 639-3 code of the Iowa-Oto language
 
https://en.wikipedia.org/wiki/IOW
I suggest that you only use official acronyms, so I think you should change it to "In other words, ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed in 034e260
        
          
                docs/api.rst
              
                Outdated
          
        
      | runStreamWithLocalTime :: Sink a -> Scheduler -> Time -> Stream a -> void | ||
| Run a :ref:`Stream`, sending all events to the provided :ref:`Sink`. The Stream will have localized :ref:`Time` values, whose origin (i.e. time 0) is at the specified Time on the provided :ref:`Scheduler`. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comma after "i.e.". So:
... whose origin (i.e., time 0)
The same goes for e.g.
Note that the comma after the abbreviations is American style. The British style omits the comma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 034e260
21cd8aa    to
    034e260      
    Compare
  
    
          
 I'm not sure I understand.  We started with  One tricky thing now is that all 3 of these functions,  I can even imagine other functions for activating a stream: -- Provide a handler for error, and a handler for end
cleverName :: (Error -> void) -> (() -> void) -> Stream a -> Scheduler -> void
-- Provide a handler for error only
cleverName2 :: (Error -> void) -> Stream a -> Scheduler -> voidWhich maybe opens the can of worms about whether returning a promise is even worthwhile. Given the first variant above, someone could easily do this to get themselves a promise: new Promise((resolve, reject) => cleverName(resolve, reject, stream, scheduler)) | 
    
| 
           A few thoughts on short names (even though I don't think short is a necessity here since these functions won't be called all that often): run runStream run  | 
    
034e260    to
    c584bea      
    Compare
  
    | 
           
  | 
    
| 
           See 46a6511, which splits stream clock localization into its own withLocalTime combinator.  Instead of needing 3 run-like functions, it means we only need 2: the existing runEffects(), and run(), where run is just the trivial function version of stream.run:   | 
    
| 
           If we like this direction, then there are a couple remaining todos: 
  | 
    
| 
           Love it 😍  | 
    
        
          
                packages/core/src/index.js.flow
              
                Outdated
          
        
      | declare export function runStreamWithLocalTime <A> (sink: Sink<A>): (scheduler: Scheduler) => (origin: Time) => (s: Stream<A>) => Disposable | ||
| declare export function runStreamWithLocalTime <A> (sink: Sink<A>, scheduler: Scheduler): (origin: Time, s: Stream<A>) => Disposable | ||
| declare export function runStreamWithLocalTime <A> (sink: Sink<A>, scheduler: Scheduler): (origin: Time) => (s: Stream<A>) => Disposable | ||
| declare export function runStreamWithLocalTime <A> (sink: Sink<A>, scheduler: Scheduler, origin: Time): (s: Stream<A>) => Disposable | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! I need to update the TS and Flow type definitions
          
  | 
    
        
          
                docs/api.rst
              
                Outdated
          
        
      | withLocalTime :: Offset -> Stream a -> Stream a | ||
| Create a Stream with localized :ref:`Time` values, whose origin (i.e., time 0) is at the specified Time on the :ref:`Scheduler` used to the Stream is observed with :ref:`runEffects` or :ref:`run`. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scheduler used to the Stream
something maybe missing here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That is not a complete sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code comment for  withLocalTime, the following text is found:
Create a stream with its own local clock
This transforms time from the provided scheduler's clock to a stream-local clock (which starts at 0), and then back to the scheduler's clock before propagating events to sink. In other words, upstream sources will see local times, and downstream sinks will see non-local (original) times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case, the code comment provides some extra detail on how withLocalTime works, which may not be appropriate for user api docs. On the other hand, the last sentence in the comment may be useful in the docs.
From your comment, I'm not sure what you're suggesting. Could you clarify? Thanks!
        
          
                docs/api.rst
              
                Outdated
          
        
      | withLocalTime :: Offset -> Stream a -> Stream a | ||
| Create a Stream with localized :ref:`Time` values, whose origin (i.e., time 0) is at the specified Time on the :ref:`Scheduler` used to the Stream is observed with :ref:`runEffects` or :ref:`run`. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That is not a complete sentence.
| Create a Stream with localized :ref:`Time` values, whose origin (i.e., time 0) is at the specified Time on the :ref:`Scheduler` used to the Stream is observed with :ref:`runEffects` or :ref:`run`. | ||
| 
               | 
          ||
| When implementing custom higher-order :ref:`Stream` combinators, such as :ref:`chain`, you should use ``withLocalTime`` to localize "inner" Streams before running them. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is chain a custom combinator that the user implements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"such as" is referring to chain as a higher-order combinator. Would you suggest removing the word "custom"?
        
          
                docs/api.rst
              
                Outdated
          
        
      | withLocalTime :: Offset -> Stream a -> Stream a | ||
| Create a Stream with localized :ref:`Time` values, whose origin (i.e., time 0) is at the specified Time on the :ref:`Scheduler` used to the Stream is observed with :ref:`runEffects` or :ref:`run`. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code comment for  withLocalTime, the following text is found:
Create a stream with its own local clock
This transforms time from the provided scheduler's clock to a stream-local clock (which starts at 0), and then back to the scheduler's clock before propagating events to sink. In other words, upstream sources will see local times, and downstream sinks will see non-local (original) times.
| import { schedulerRelativeTo } from '@most/scheduler' | ||
| 
               | 
          ||
| // Run a stream with its own localized clock | ||
| // Create a stream with its own local clock | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... with its own local clock
Do we also have a clock type? I know there is  Time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmokay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 row it
| 
           🎉  | 
    
Add
runStreamas the function form ofstream.run.Open questions
Argument ordering. It's not clear what the "right" argument ordering is. Since the subject of the function is a Stream, the obvious choice is to make it last. After that, though, it's less clear.
Consider that we have two other, similar functions, and it might be nice to have some coherent criteria for ordering the arguments across
runStreamand these:runEffects :: Stream -> Scheduler, andrunWithLocalTime :: Offset -> Stream a -> Sink a -> Schedulerstream.run, i.e. sink, scheduler. Maybe it makes sense to move the Stream to the last arg to end up withOffset -> Sink a -> Scheduler -> Stream a, which is similar torunStreamwith the extraOffsetarg prepended.Thoughts and suggestions welcome!
Todo