low level is sh*t level

4 views
Skip to first unread message

Raoul Duke

unread,
Apr 21, 2026, 8:23:00 PM (6 days ago) Apr 21
to pi...@googlegroups.com
if your (or my) language needs a trick for something everybody ends up wanting to do then it kind of sucks. 

Mike Austin

unread,
Apr 23, 2026, 5:04:51 PM (4 days ago) Apr 23
to PiLuD
I use this all the time. I guess it's not the prettiest. To conditionally add an array element:

  return [
    ...(data.age ? [data.age] : []),
  };

It works, but how could it be better?

Raoul Duke

unread,
Apr 23, 2026, 5:58:37 PM (4 days ago) Apr 23
to pi...@googlegroups.com
a better language 

--
You received this message because you are subscribed to the Google Groups "PiLuD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pilud+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pilud/1b62bf26-dddd-4688-b046-4f922e235e68n%40googlegroups.com.

Mike Austin

unread,
Apr 24, 2026, 12:57:07 PM (3 days ago) Apr 24
to PiLuD
Sure. What would the syntax look like?

Another way is building up the array. It still takes a good amount of logic:

  array = []
  array = data.age ? [...data, data.age] : array

Maybe an operator?

  return [
    data.age ?[] data.age,
  };

Mike Austin

unread,
Apr 24, 2026, 5:06:24 PM (3 days ago) Apr 24
to PiLuD
Straight out of today's code:

  const epics = items.reduce((epics, { epic }) => ({
    ...epics,
    ...(epic !== null && { [epic.id]: epic }),
  }), {} as Record<"string", { title: string }>);

I could filter out null epics first, but they could still be null to the type-checker. The "as" is boilerplate to use and empty object as the initial value.
Reply all
Reply to author
Forward
0 new messages