Slicing a Consumable List

Is there a simple way to to make a consumableList of a subset of the larger list?

I’d like something like the following

originalList
  A
  B
  C
  D

[a = originalList.selectmany(2).consumableList]

in my dream, [a] should be a consumable list of two random elements from originalList.

Thanks!

5 points · 3 comments · view on lemmy.world

3 Comments

Koto@lemmy.world · 2 pts · 1y (2 replies)

Yes, it's possible. The correct syntax would be [a = originalList.consumableList.selectMany(2)] . Then, we'll need to make a list of that slice by using createPerchanceTree() with the correct escape characters. The function works like this: [newList = createPerchanceTree("slicedList\n\ta\n\tb").slicedList] [newList]

danMiller@lemmy.world · 1 pts · 1y (1 reply)

If I understand this correctly, I think I lose having a consumable list as the final output. But it got me on the right track I think. THANKYOU!

I’m working with this now, which seems to produce a functional consumable list derived from a slice of the original list.

thanks again, I hadn’t stumbled across the createPerchanceTree command in the tutorials.

OriginalList
  d
  c
  x
  y
  z

//calls consumableList here just to prevent duplication
a = \{  [OriginalList.consumableList.selectMany(2).joinItems("|")]  \}

output
  //converts the selectmany product to a consumableList
  [newList = createPerchanceTree("slicedList =" + a ).slicedList.consumableList] [newList] [newList]  




Koto@lemmy.world · 1 pts · 1y

You won't be losing consumable list on that created list, as you can .consumableList it again. Judging by your code, you figured it out!