For example, I'd like to turn "hello"
into list(104, 101, 108, 108, 111)
or list("h", "e", "l", "l", "o")
So far I've created an empty list, used foreach
and appended every item to the list myself, but that's not really a concise way to do it.
My own suggestion:
Sequence asList := method(
result := list()
self foreach(x,
result append(x)
)
)
Haven't tested it performance-wise but avoiding the regexp should account for something.
Another nicely concise but still unfortunately slower than the foreach
solution is:
Sequence asList := method (
Range 0 to(self size - 1) map (v, self at(v) asCharacter)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With