Skip to content
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

Remove type constraint on Stream/Sink/Store type variable #14

Open
dwhitney opened this issue Apr 9, 2019 · 3 comments
Open

Remove type constraint on Stream/Sink/Store type variable #14

dwhitney opened this issue Apr 9, 2019 · 3 comments

Comments

@dwhitney
Copy link

dwhitney commented Apr 9, 2019

Hey everyone,

In the Typescript type definition there is a type constraint on all of the Stream-spec types of Q extends BaseQuad = Quad. I propose removing this constraint. With the constraint in place, the data structure is pretty useless. By removing the constraint one can define Functor, Applicative, Traversable, Monad, etc., instances for Stream, which will give you functionality like map, chain/flatMap, filter, fold, traverse, sequence, etc. for free!

The reason this can't be done with the constraint in place is a the definition of map, for example, must allow the mapping from a general type A to a general type B inside of the Functor. Because Stream is constraining the type variable to Q extends BaseQuad, a general function mapping can't be applied and so Stream can't be treated as a Functor.

If it's desired to have a stream with the type variable fixed with Q extends BaseQuad = Quad, one could be provided out of the box, like

interface RDFStream<Q extends BaseQuad = Quad> extends Stream<Q> { 
...
}

or you could just let the user define one themselves.

Just to give an example of what could be done after the constraint is removed and the appropriate type class instances are implemented:

  • fold over a Stream<Quad> to produce Either<Error, User>
  • traverse over a Stream<Quad> to produce Stream<User>
  • chain over a Stream<Quad> of a SHACL shapes, where owl:import statements are resolved and a new Stream<Quad> is produced, and then fold could be used to reduce some data structure representing a "Shape"

Thoughts?

@dwhitney
Copy link
Author

dwhitney commented Apr 9, 2019

looking closer at the types you could keep the type constraint on the Source type

@elf-pavlik elf-pavlik transferred this issue from rdfjs/data-model-spec Apr 9, 2019
@elf-pavlik
Copy link
Member

RDFJS Stream interfaces now have dedicated repo and i transferred this issue to it. This looks relevant to #2

@rubensworks
Copy link
Member

There is indeed definitely a need for using/creating a more generic stream interface (see #2), that is not tied to quads. Let's put this on hold until #2 is resolved. I can update the TS definitions afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants