this function could also go in utils, but that is not a big thing. (Side note, I have actually written my own little helper function for this while I have been working on the data structures, so it might be of common enough use.)