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 collection.find() ? #163

Open
dylans opened this issue Nov 23, 2015 · 1 comment
Open

Add collection.find() ? #163

dylans opened this issue Nov 23, 2015 · 1 comment

Comments

@dylans
Copy link

dylans commented Nov 23, 2015

Suggestion was made from a relatively new user of dstore to add collection.find() to return exactly one/first item. Currently need to use filter()[0] .

Adding it here to consider.

@kitsonk
Copy link
Contributor

kitsonk commented Nov 24, 2015

Worth considering, but challenges I can see with an API like that is that it sort of leads to really bad usage. It sort of indicates that it is a grab bag of results, magically return the "first" object... Who's first object? Also that sort of API also has no way of saying to the user "I found lots of stuff, are you sure you only want the first one". I have seen similar sorts of things lead to all sorts of logic errors or unexpected results.

I am struggling to think of a valid use case where it wouldn't lead to someone shooting themselves in the foot.

If anything, I would prefer to see something like .first() where the API requires some explicit resolution logic of what "first" means so it isn't arbitrary. Of course that lends itself to some sort of Iterator API, which is something I have been thinking about for "dstore 2" which would be able to provide native/polyfilled iterators as well as delta change API.

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

No branches or pull requests

2 participants