Open dwhitney opened 5 years ago
looking closer at the types you could keep the type constraint on the Source
type
RDFJS Stream interfaces now have dedicated repo and i transferred this issue to it. This looks relevant to #2
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.
Hey everyone,
In the Typescript type definition there is a type constraint on all of the
Stream-spec
types ofQ 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 forStream
, which will give you functionality likemap
,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 typeA
to a general typeB
inside of theFunctor
. BecauseStream
is constraining the type variable toQ extends BaseQuad
, a general function mapping can't be applied and soStream
can't be treated as aFunctor
.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, likeor 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 aStream<Quad>
to produceEither<Error, User>
traverse
over aStream<Quad>
to produceStream<User>
chain
over aStream<Quad>
of a SHACL shapes, whereowl:import
statements are resolved and a newStream<Quad>
is produced, and thenfold
could be used to reduce some data structure representing a "Shape"Thoughts?