Does anyone else ever have the urge to replace std...
# advent-of-code
k
Does anyone else ever have the urge to replace stdlib methods for Advent of Code or am I the only one?
nod 1
n
Which ones for example?
n
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
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
I think for that case I'd likely add a
Iterable.allMinBy
and chain it with
single
n
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
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
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
@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