Add a few Stdlib helpers
- String.capitalize
- String.isEmpty
- Dict.size
- Dict.isEmpty
- Array.isEmpty
- Map.isEmpty
- Set.isEmpty
Let me know if I need to cherry-pick some changes.
rescript
npm i https://pkg.pr.new/rescript-lang/rescript@7516
@rescript/darwin-arm64
npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7516
@rescript/darwin-x64
npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7516
@rescript/linux-arm64
npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7516
@rescript/linux-x64
npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7516
@rescript/win32-x64
npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7516
commit: 669de38
I like these. @cknitt what do you think?
@DZakh could you rebase?
I like these. @cknitt what do you think?
Certainly useful, my only concern is that Dict.size and Dict.empty sort of hide their performance implications (array allocation, O(n)).
Actually they could be implemented without the array allocation:
function size(dict) {
let count = 0;
for (let key in dict) {
if (dict.hasOwnProperty(key)) count++;
}
return count;
}
Done, here's the benchmark.
You can see how everything is ~5-10% faster than Object.keys version. Where Dict.isEmpty is two times faster.
The hasOwnProperty is not needed, since this is how for..in works anyways.
Try running make test-analysis to update those snapshots.
@nojaf I get the following error:
Package name mismatch for /Users/dzakh/code/DZakh/rescript/tests/analysis_tests/tests:
The package.json name is "@tests/analysis", while the rescript.json name is "test"
This inconsistency will cause issues with package resolution.
WARN:
Package name mismatch for /Users/dzakh/code/DZakh/rescript/tests/dependencies/rescript-react:
The package.json name is "@tests/rescript-react", while the rescript.json name is "@rescript/react"
This inconsistency will cause issues with package resolution.
[1/2] 🧹 Cleaned compiler assets in 0.00s
[2/2] 🧹 Cleaning .res.js files...
thread 'main' panicked at src/build/clean.rs:68:78:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make[1]: *** [clean] Error 101
make: *** [clean] Error 2
Yeah, I've seen this one.
Try and replace rescript clean with rescript legacy clean in the package.json files of those test projects.