A few comments on this function:
 - I think you are already checking for null values below, so these cases will never match.
 - In match statements you can use _ to denote values where you do not need to check the value or use it.
 - I'm not sure why this is a partial function.  Since you are lifting the partial function and using `get` to retrieve the result, it ends up being equivalent to just using a `match` statement, which would be syntactically much simpler.
 - The use of tuples as arguments to functions should be discouraged.  Where there is a very clear `(key,value)` relationship or when they are only used locally it is maybe okay, but here it is very difficult to trace what the arguments to this function are supposed to be.
 - Given the above, I'd remove this PartialFunction and just embed the last case in the `apply` function.