I'm trying to do this:
Stack Overflow link
... but my brain is tired. I'll come back to it.