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

Add DataFactory method to create from existing term #137

Closed
RubenVerborgh opened this issue Jan 15, 2019 · 9 comments
Closed

Add DataFactory method to create from existing term #137

RubenVerborgh opened this issue Jan 15, 2019 · 9 comments

Comments

@RubenVerborgh
Copy link
Member

We want to consider adding a method to DataFactory that takes a Term-shaped object (from any library) as input, and outputs a Term (from the library of the DataFactory) that equals it.

This can be used to convert a Term from one RDF/JS implementation to another.

@rubensworks
Copy link
Member

For consistency, we may also want add a similar method for converting Quad objects.

@elf-pavlik
Copy link
Member

I could make PR for DataFactory#clone()

(Term or Quad) clone((Term or Quad) other)

I think in this case we don't allow undefined or null

@rubensworks
Copy link
Member

@elf-pavlik I would propose creating separate methods for cloning terms and quads (cloneTerm, cloneQuad). Implementations may otherwise become too complicated for determining the argument type.

@RubenVerborgh
Copy link
Member Author

fromTerm/fromQuad?

@bergos
Copy link
Member

bergos commented Feb 11, 2019

👎 for .clone(), as this could be interpreted as a clone function of the factory itself. It doesn't make sense now, but maybe in the future we have an additional spec (Prefix + CURIE support which turns the DataFactory into an environment) were having multiple instance of the DataFactory makes more sense.

I favor fromTerm and fromQuad a little bit over cloneTerm and cloneQuad. from* indicates much stronger that new instances by the DataFactory are created and not that somehow the constructor of the given Term/Quad is used.

@elf-pavlik
Copy link
Member

fromTerm & fromQuad SGTM, if no one else makes PR today/tomorrow I'll submit one on Wednesday

@elf-pavlik
Copy link
Member

PR #158

elf-pavlik added a commit that referenced this issue Apr 15, 2019
DataFactory methods to create from existing term and quad | closes #137
@awwright
Copy link
Member

Sorry I just noticed this, but I'm curious... Why not pass a plain object to the Term or Quad functions directly?

@elf-pavlik
Copy link
Member

As I replied on https://gitter.im/rdfjs/public?at=5cb48398c55bd14d35ebcf88 single factory object makes it much easier to pass it around. Spec only defines methods on the factory and doesn't define any constructors for specific terms.

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

No branches or pull requests

5 participants