Code Monkey home page Code Monkey logo

Comments (3)

neurosnap avatar neurosnap commented on August 28, 2024

This poses another question: yielding to a bare object is really cool and pretty to look at but a little confusing to understand. For example yielding to a stream to create a subscription:

function*() {
  const subscription = yield* stream;
}

I wonder if it would be easier for end-users to grok something more like this:

function*() {
  const subscription = yield* stream();
  // or
  const subscription = yield* stream.subscription();
}

Just thinking through the implications of this API change as well as being consistent across-the-board.

from effection.

cowboyd avatar cowboyd commented on August 28, 2024

This is a really interesting point. So basically, you're saying that a stream should be:

type Stream<T, TClose> = () => Operation<Subscription<T, TClose>>;

Or rather stream should stay the same, and that the convention should be to return functions that return them? For example that the type of something likeChannel should be:

interface Channel<T, TClose> {
  //...
  stream(): Stream<T,TClose>;
}

because at the end of the day, a Stream is really just a very specific kind of resource.

I'd almost say that the right call is to have Channel be something like:

interface Channel<T, TClose> {  
  send(value: T): Operation<void>;
  close(value: TClose): Operation<void>;
  subscribe(): Stream<T, TClose>;
}

Which is confusing, but makes sense when you think of what a stream really is which is just an operation that yields a subscription. If we expand the type, it makes more sense.

interface Channel<T, TClose> {
  send(value: T): Operation<void>;
  close(value: TClose): Operation<void>;
  subscribe(): Operation<Subscription<T, TClose>>;
}

Maybe that's the answer?

from effection.

cowboyd avatar cowboyd commented on August 28, 2024

Another option is to make the Stream interface:

interface Stream<T, TClose> {
  subscribe(): Operation<Subscription<T, TClose>>;
}

It's a very small change, but it might reduce confusion by quite a bit. Everything would continue to work the same, but instead of saying yield* stream, you would just say yield* stream.subscribe()

yield* each(stream) would continue continue to work, but any time you're manually iterating a stream it would be a bit less confusing.

from effection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.