sopel-irc / sopel-rainbow

A Sopel plugin to make things RAINBOW COLORED.
Other
0 stars 0 forks source link

Implement ALL the things #1

Closed dgw closed 4 years ago

dgw commented 4 years ago

Oh yeah, it's configurable. I had to.

Exirel commented 4 years ago

If you want to be very fancy, you can use cycle and a list-comprehension:

color_iterable = itertools.cycle(colors)
''.join(
    char if unicodedata.category(char) == 'Zs'
    else formatting.color(char, next(color_iterable))
    for char in text
)

And to randomize it:

for _ in range(random.randint(len(colors))):
    next(color_iterable)

Totally unnecessary so I had to do it.

dgw commented 4 years ago

A quick timeit experiment shows that it's faster to set up deques, and faster to iterate over cycles (which makes sense).

But I'm too lazy to set up all the boilerplate that would let me actually test both whole implementations—and much too lazy to set up instrumentation that would let me profile the memory usage/bandwidth of each approach—so let's just let @Exirel make the code fancier by proxy. 😼