Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world
perchance·Perchance - Create a Random Text GeneratorbydanMiller

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!

View original on lemmy.world
5

3 replies

lemmy.world

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]

2
danMillerreply
lemmy.world

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]  




1

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!

1

You reached the end

Slicing a Consumable List | Spyke