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 find_one method. #42

Open
XAMPPRocky opened this issue Aug 9, 2017 · 5 comments
Open

Add find_one method. #42

XAMPPRocky opened this issue Aug 9, 2017 · 5 comments

Comments

@XAMPPRocky
Copy link

Currently just to find a single element requires a bit of boilerplate. Consider adding a a find_one method that returns Option<Node>.

@utkarshkukreti
Copy link
Owner

You could do .find(predicate).next(). Or is that what you mean by "a bit of boilerplate"?

@XAMPPRocky
Copy link
Author

The boilerplate is not so much in the number of characters as document.find_one(pred).unwrap() is close to document.find(pred).next().unwrap() it's more the boilerplate of only returning collection types, especially when a lot of them could be single element collections.

@HighCommander4
Copy link

HighCommander4 commented Oct 7, 2018

Actually, it's not quite the same. I think find_one() should return None if there are two or more nodes in the selection, too.

@XAMPPRocky
Copy link
Author

@HighCommander4 I don't think that is intuitive. I've never found myself commonly needing to require that a query result is completely unique. This would be a lot easier to convey through document.find(pred).size_hint()/document.find(pred).collect::<Vec<_>>().len() == 1

@tversteeg
Copy link

If it shouldn't be unique, shouldn't it be called find_first instead?

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

4 participants