DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.35k stars 29 forks source link

Semiautovivification #487

Open anhnhoktvn opened 1 year ago

anhnhoktvn commented 1 year ago

It's nice to have Semiautovivification from livescript Screenshot_2023-04-01_10-12-33

STRd6 commented 1 year ago

We can currently do something similar with:

x = {}
(x.'hello world' ?= []).2 = 3

I'm not convinced that an additional specialized syntax is worth it in this case.

anhnhoktvn commented 1 year ago

I just used it a lot in past. Quite elegant. How do we do this

x.[]arr.{}1.y = 9

in Civet way?

STRd6 commented 1 year ago

Currently:

( ( x.arr ?= [] )[1] ?= {} ).y = 9

It may make sense to try something like this for a possible future syntax:

x.arr?=[][1]?={}.y = 9
STRd6 commented 6 months ago

Now that we have pipes:

x |> .foo ?= [] |> .append 5
x |> .foo ?= {} |> &[key] ?= [] |> .push value
(x.foo ??= []).append(5);
((x.foo ??= {})[key] ??= []).push(value);