-
Notifications
You must be signed in to change notification settings - Fork 2
Description
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:
foldover aStream<Quad>to produceEither<Error, User>traverseover aStream<Quad>to produceStream<User>chainover aStream<Quad>of a SHACL shapes, whereowl:importstatements are resolved and a newStream<Quad>is produced, and thenfoldcould be used to reduce some data structure representing a "Shape"
Thoughts?