• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moonbitlang / core / 4207
95%

Build:
DEFAULT BRANCH: main
Ran 06 May 2026 12:37AM UTC
Jobs 1
Files 364
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

06 May 2026 12:36AM UTC coverage: 94.615% (-0.002%) from 94.617%
4207

push

github

bobzhang
refactor: build Map from comprehension instead of mutating loop

Following the pattern in builtin/json.mbt (Map.to_json), apply the same
"build Map without mutation" idiom across three more sites:

- sorted_map/utils.mbt SortedMap::to_json
- immut/sorted_map/traits_impl.mbt SortedMap::to_json
- argparse/parser_lookup.mbt build_long_index

Each had `let m = Map([], capacity=...)` followed by an imperative
populating loop. Replaced with a single Map comprehension expression:

```diff
-pub impl[K : Show, V : ToJson] ToJson for SortedMap[K, V] with to_json(self) {
-  let capacity = self.length()
-  guard capacity != 0 else { return Json::object(Map([])) }
-  let jsons = Map([], capacity~)
-  self.each((k, v) => jsons[k.to_string()] = v.to_json())
-  Json::object(jsons)
+pub impl[K : Show, V : ToJson] ToJson for SortedMap[K, V] with to_json(self) {
+  Json::object(
+    Map(
+      capacity=self.length(),
+      [for k, v in self => (k.to_string(), v.to_json())],
+    ),
+  )
 }
```

`build_long_index` collapses the same way that `build_short_index`
already did (in #3522). The `guard capacity != 0` early-return is
removed because `Map::Map` already handles capacity=0 (it bumps to
`default_init_capacity`).

Style: labeled args (`capacity=...`) before positional, per maintainer
preference.

Semantics-preserving: full `moon test` (6425/6425) passes and
`moon info` produces no `.mbti` change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

7 of 7 new or added lines in 3 files covered. (100.0%)

14829 of 15673 relevant lines covered (94.61%)

218945.62 hits per line

Jobs
ID Job ID Ran Files Coverage
1 4207.1 06 May 2026 12:37AM UTC 365
94.62
GitHub Action Run
Source Files on build 4207
  • Tree
  • List 364
  • Changed 3
  • Source Changed 3
  • Coverage Changed 3
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • 67b8afa9 on github
  • Prev Build on main (#4201)
  • Next Build on main (#4210)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc