question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should `findSingle` has the default predicate?

See original GitHub issue

findSingle in collections module has the default selector predicate of (_) => true. Does this make sense? What’s the use case?

context of this discussion: https://github.com/denoland/deno_std/pull/1166#issuecomment-917268388

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
timreichencommented, Sep 15, 2021

Just for completeness here the reasons why I find we should remove the default predicate

  • the name findSingle corresponds to find and findIndex which have a mandatory predicate.
  • these cases all return the same value with the default predicate which does not give the user a clue, if the array is empty, has a single unique value or not:
findSingle([]) // returns undefined
findSingle([undefined]) // returns undefined
findSingle([undefined, undefined]) // returns undefined
1reaction
timreichencommented, May 23, 2022

@kt3k I think this issue can be closed since the PR got merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Among Find, Single, First, which one is the fastest?
Find is actually closer to FirstOrDefault, as Find will return the default if no match is found. First will throw an exception. Single:...
Read more >
TypeScript Type Guards and Type Predicates
A type guard is an expression that performs a runtime check that guarantees the type in the current scope. The quick fix is...
Read more >
Java 8 Stream filter() + findFirst Example Tutorial
You can use the Stream class along with filter() and findFirst() methods to find out an element based upon a Predicate, a functional...
Read more >
Automatically Generating Predicates and Solutions for ...
We followed three goals in designing our automated predicate extraction system. 3.1 Minimize false positives. Automatically inferring user intentions is a hard ...
Read more >
List<T>.Find(Predicate<T>) Method
If the default value satisfies the search predicate, use the FindIndex method instead. This method performs a linear search; therefore, this method is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found