The other answers were close but I figured out how to accomplish what I was after with the following function