Sadly no - collectFirst takes a partial function (in this case PartialFunction[(Instruction, Int), Int]) which I can't wrangle the input collection into. It's a bit of a 'square peg round hole' situation. I should probably craft something myself for such a case.
In your code snippet the case would be satisfied on the first instruction and I would then get a NoSuchElementException.
Just as a side note whilst it has re-entered my mind: I really like reading through your solutions and have got a better impression of 'functional Python' from seeing how you approach the problems.
Sadly no -
collectFirst
takes a partial function (in this casePartialFunction[(Instruction, Int), Int]
) which I can't wrangle theinput
collection into. It's a bit of a 'square peg round hole' situation. I should probably craft something myself for such a case.In your code snippet the case would be satisfied on the first instruction and I would then get a
NoSuchElementException
.