https://kotlinlang.org logo
#advent-of-code
Title
# advent-of-code
k

Kroppeb

12/02/2023, 8:53 AM
Does anyone else ever have the urge to replace stdlib methods for Advent of Code or am I the only one?
nod 1
n

NotEvenJoking

12/02/2023, 8:59 AM
Which ones for example?
n

Neil Banman

12/02/2023, 9:24 AM
No… not really. Do you mean signatures (functionality) or implementation? Sometimes I think the std implementation has too much ceremony but I generally assume there’s an optimization or edge case I’m not seeing. I’ve come to see the wisdom in having the map/filter family default to List. I wish they added indexed versions to all the Iterable and Sequence extensions, but withIndex is cheap and it’s easy to add extra extensions.
k

Kroppeb

12/02/2023, 9:24 AM
Some of my functions has sanity checks that will produce a warning (once) if something unexpected passes by. An example I would "want" to replace is
Iterable.minBy
and make it warn if there are multiple elements that have the minimum value. This would never make sense in the standard lib, but would would mean I find errors faster (like maybe I make a mistake and return 0 by accident for every time the lambda gets invoked)
I don't really care too much about small performance improvements for aoc
p

phldavies

12/02/2023, 10:59 AM
I think for that case I'd likely add a
Iterable.allMinBy
and chain it with
single
n

NotEvenJoking

12/02/2023, 11:31 AM
I don't think they meant this case in particular, just in general doing sanity checks in order to not have to worry about the mistakes that might pop up during (speed) solving problems.
j

Jakub Gwóźdź

12/02/2023, 5:30 PM
Sometimes I believe there could be more shorthand methods, e.g. reading Int from
(\d+) blue
regex requires a lot of boilerplate. But I don't lose much sleep over it 🙂
n

Neil Banman

12/02/2023, 8:34 PM
I have played around with ways for a regex to automatically return some kind of tuple. I wrote a slow and cumbersome parse function that takes in an object and uses reflection to get the types and converts group values to those types. But it doesn’t save much or any time coding and execution is slow, so I never use it.
y

y9san9

12/03/2023, 11:30 AM
@Kroppeb not exactly, but I write a LOT of utility functions. By biggest surprise was that there is no indexOfOrNull function, so you have to do indexOf { ... }.takeIf { it != 1 }
1
10 Views