Comments (5)
Hi lpil, I've started working on this.
The only down side I can see so far is the readability of the output JS for long lists. Do we particularly care about that?
e.g.
this is pretty ugly (although from my testing, the fastest)
new $NonEmpty(1, new $NonEmpty(2, new $NonEmpty(3, new $Empty())))
We could put a cons function in the prelude which would help clean it up a bit, and empty can be a constant. The cons function adds very minor overhead, imo negligible. These could also have even shorter aliases in the import (?).
$cons(1, $cons(2, $cons(3, $EMPTY)))
Another idea is switching back to toList
when there are many elements added at once, say >2 or so. Could be used in combination with aliases of course.
from gleam.
I'm surprised there's quite such a different as toList(first, rest)
is just first.reduceRight((xs, x) => new NonEmpty(x, xs), rest);
, but any faster approach would be gladly accepted.
from gleam.
Wonderful! Thank you.
An alias could be good too, rather than a function wrapper. There would be no overhead in that case.
Would just a single character such as $ be too opaque? Assuming that one is free.
from gleam.
The problem with an alias without the wrapper function is that you still need to put the new
keyword every time, so the minimum you can get is 5 characters.
Single character is fine with me 🤷
$ is being used for asserts though (probably could free it up)
What should we do about lists without a rest param e.g. just [1,2,3,4,5]
?
I imagine they have the same performance gain to be had from switching, but also they are more likely to be large and thus ugly.
from gleam.
My thoughts after some testing:
- Wrapper function good. Seems to make things more predictable for some reason.
- Single character was hard to read, I think just go with $prepend. The vast majority of prepends are just one item anyway.
- Leave lists that are not prepends as-is. I didn't measure a performance improvement from changing these.
from gleam.
Related Issues (20)
- LSP: Goto Definition not working properly for unqualified imports HOT 2
- (hex)docs: types in function signatures should be clickable links to their documentation HOT 1
- Deprecate `..` discard if not preceded by a comma HOT 1
- Improve the error message for using module alias as a name HOT 2
- LSP code action: turn (wrong) C-style type definition into a single constructor type HOT 1
- Gleam package manager seems to default to oldest possible version instead of most recent HOT 1
- Language Server: Label access completion only works with public types
- `gleam export package-interface` breaks when build is cached HOT 3
- lsp crash HOT 1
- gleam doesn't update, on AUR helper (yay) HOT 3
- Infer minimum Gleam version HOT 5
- Allow Strings in a BitArray literal without having to specify utf8 encoding HOT 3
- Print progress to stderr, not stdout HOT 3
- LSP: autocompleting type imports should add brackets if needed HOT 1
- string.drop_left appears to return array of ASCII codes in some circumstances HOT 2
- Inconsistency with tag name format expected for source links in docs based on repository type HOT 4
- Add hint to error message when trying to use a variable name starting with a `_` HOT 2
- Compiler crash when checking exhaustiveness of a pattern on a type with duplicate variants HOT 2
- LSP: function hover info should include argument labels HOT 1
- error: Fatal compiler bug! Double records name is the problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gleam.