-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adds toSet to create sets from iterables #16276
Conversation
Thank you for all your comments/insight, the latest commit should check all of the boxes, atleast as far as I know. |
I'm inept with the rebase :D |
There we go this should be fine now, thanks. |
lib/std/setutils.nim
Outdated
assert toSet([false]) == {false} | ||
assert toSet(0u8..10u8) == {0u8..10u8} | ||
type E = elementType(iter) | ||
static: doAssert E is SetElement, "`iter` does not yield a `SetElement`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, why do we even need the static: doAssert E is SetElement
?
you'll still get an error when attempting var result: set[E]
if say, E is int64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the main reason is to give a slightly more informative error instead of just set is to large
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we should fix the errmsg in the compiler, where it belongs (which would benefit other code):
nim> var z: set[int]
Error: set is too large
=>
Error: set is too large, got `int` but expected ...
LGTM, thanks! I restarted CI, you're hitting windows flaky test timotheecour#411 (EDIT: reported it as #16317) |
now you're hitting a different CI issue I haven't seen before (timotheecour#441); I restarted failing job |
Leave it to me to hit issues no one has hit before. |
just bikeshedding but another candidate name would be: I'm ok with either, though |
Do you mean |
well by definition they're builtin ;-) ; |
So ... rather than |
intended use case is not for cases where input is a litteral (in which case you'd write examples: let input: string = getInput()
let uniqueLetters = input.toSet # or: callFn(input.toSet) I've often needed this myself as well, it fits well with the rest of stdlib:
to the point that not having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks.
@beef331 you can click "Resolve Conversation" on each item that was resolved (unless there's a disagreement) :) |
hitting #16317 again; I've restarted failing tests |
Needs a changelog entry and maybe (!) a ```--define:nimHasSetUtils`` (edit compiler/condsysm.nim to add it). |
indeed
this hasn't been needed for other new modules, and in fact will be obsoleted by |
changelog.md
Outdated
@@ -57,6 +57,8 @@ | |||
|
|||
- `strscans.scanf` now supports parsing single characters. | |||
|
|||
- Added `setutils.toSet` that can take any iteratable and convert it to a built-in set, | |||
if the iteratable yields a built-in settable type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iteratable
doesn't seem enligh; should be iterable
merged; previous CI was green and last commit just changed changelog. |
Replicates the
toHashSet
proc for normal sets.