hotscript
hotscript copied to clipboard
Numbers
The tuple trick to do number operations is really limited.
I have a complete implementation here with no limitations but ts memory and compute power : https://github.com/ecyrbe/ts-calc
But it would be really out of scope, maybe ?
Sharing anyway just in case.
Could these libraries cooperate? Single responsibilities and all :)
Your library looks amazing. I think what's in scope or out of scope for HOTScript is very much up for debate, but I'd love to improve the Number module with something that's less limited.
Manipulating numbers to keep track of indices, or add lengths togethers, or pick the largest / smallest between two number are super common use cases when writing loops, so if you want to contribute to the number module to add:
- N.Add
- N.Multiply
- N.Substract
- N.GreaterThan
- N.GreaterThanOrEqual
- N.LessThan
- N.LessThanOrEqual
I think that would make an awesome addition 😀
Ideally all of these should be "semi-pipeable" (or curried?), e.g. they could be used like this:
// all arguments can come from piped inputs
type T = Call<Tuples.Reduce<Numbers.Add, 0>, [1, 2, 3]>
// ^? 6
// one explicit arg, one from piped inputs
type T = Call<Tuples.Map<Numbers.Add<2>>, [1, 2, 3]>
// ^? [3, 4, 5]
// two explicit args
type T = Eval<Numbers.Add<2, 3>>
// ^? 5
Add
already works like this so I'm pretty confident this is doable: https://github.com/gvergnaud/PipeScript/blob/4e0e8de1b17adfa5fce751ee637b444f06e19443/test/HOTScript.test.ts#L363-L384
Would you mind if we create a sub directory for internals (all Impl stuff) ? because importing Number operations in HOTScript.ts will likely make it really hard to check :
src/
| - internal/
|- number/
|- object/
...
|- HOTScript.ts
Yeah I definitely think we should do that. Will update the structure of the main branch
@ecyrbe done, with this structure it should be little easier to have several contributors!