It might be OK to relax the error semantics as long as you don't report that K is a key when the first found entry with key K is not a pair. So you could use keyfind to look it up, and return true in case of a pair and raise function_clause otherwise.