Hello. I'm using something like this ["{red, blue, green, orange, lime}".selectMany(3).joinItems(", ")]. It works well enough, but when I try to implement uniqueSelect or consumableList it fails. These function seem to only work for lists but is there any way to select items from a string like that without repetition. Thanks!
3 Comments
VioneT@lemmy.world · 1 pts · 1y
Do you mean
{red|blue|green|orange|lime}with 'shorthand lists'?Well, it is because
"{red|blue|green|orange|lime}"is only one and is a string. You can use.selectMany()because, it would essentially select the same string multiple times, and when it is evaluated by the engine it would then select from those items in the string.You can't use
.selectUnique()since it is a single item, a single string. Same with.consumableListsince it isn't a list, it is a string.Best way is to have those into a list themselves:
And then, you can use those
.selectUniqueand.consumableListmethods like so[colors.selectUnique(3).joinItems(", ")]or[x = colorsV2.consumableList, ''] [x.selectOne], [x.selectOne], [x.selectOne].Koto@lemmy.world · 1 pts · 1y
Thanks, VioneT, it's not the first time you help me. I understand the mistake now. I need a list, not a choice of one. But is there a way to create the following example: "one,two,three,four".consumableList.select(3)? It should have many items even though it's a string? This example example doesn't work, of course. I just don't wanna create infinite lists for one time use.
VioneT@lemmy.world · 2 pts · 1y
Sadly, lists created from a string doesn't work like that. If you want to create a list inline, you can do this instead.
I would still recommend it to be on the list forms that I've previously shown for readability and refactorability since if you have many of those one lines, it makes it hard to debug/see problems.