Repository navigation
stdlib: add indexOf, flatMap and toInt - #263
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
e3e364d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4e42aea3.dang-3kk.pages.dev |
| Branch Preview URL: | https://stdlib-list-helpers.dang-3kk.pages.dev |
dagger/dagger.io#5802 hand-wrote an indicesOf helper and flattened lists with reduce([]) { all, e => all + e.args }. - [T]!.indexOf(element) -> Int: null when absent, not -1, since absence is null in Dang. - [T]!.flatMap { x, i => [U]! } -> [U]!, taking the index like map. - String!.toInt(base: Int = 10) -> Int!: bases 2 to 36, raising on invalid input or overflow. `s :: Int!` doesn't parse and JSON.decode only covers base 10. The skill's stdlib reference and the collections/strings docs pages cover them. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
stdlib-list-helpers
branch
from
November 8, 2026 22:54
fe1451e to
e3e364d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dagger/dagger.io#5802 (
.dagger/modules/dagger-io-dev/module_index.dang, as off0c20d2) still works around two gaps:
indicesOf(line 404), used byroleIndexasindicesOf(roles, role)[0] ?? -1(line 1017)roles.indexOf(role) ?? -1draft.entries.reduce([]) { all, e => all + e.args }(line 984; alsomodule_index_tests.dangline 322)draft.entries.flatMap { e => e.args }renderRedirects(lines 846–847) also callsindicesOf, but it needs everymatch (it checks there is exactly one), so
indexOfdoesn't replace that use.f0c20d2 already dropped the hex lookup tables (
pathUnescapeusesJSON.decodenow), buttoInt(base:)stays: it fills a real gap, sincenothing parses a non-decimal integer from a string.
sumis no longer part of this PR. It moves to a follow-up that types itthrough a built-in
Numericconstraint (sum[a: Numeric]), built on thetype-parameter work, instead of a builtin-only typing hook.
What's added
[T]!.indexOf(element: T) -> Int: the index of the first equal element(Dang equality, like
.contains), or null when the element is absent.It returns null rather than -1 because in Dang, errors are for errors and
null is for absence.
.findandxs[99]already work that way.[T]!.flatMap { x, i => [U]! } -> [U]!: map, then concatenate. Theblock takes the index, like
.mapdoes.String!.toInt(base: Int = 10) -> Int!: accepts bases 2 to 36, lettersin either case, and an optional sign. It raises on whitespace,
0x,_, anyother invalid input, or overflow. Nothing covered this before: a
"42" :: Int!cast is a type error, andJSON.decodeonly handles base 10. The namefollows
toUpper/toBase64.Docs and tests
stdlib.md(needed byTestStdlibSkillCoversBuiltins), theSKILL.mdidioms, and the "no hexliterals" note in
syntax.md. The collections and strings docs pages havelive examples.
tests/test_*.dangspecimens, and an error golden for invalid
toIntinput.pkg/dang,pkg/lsp,docs/go,tests,docsandfmt/stalepass.