Added an example using when.

I thought this would be a nice example to have. Not sure if this should be against wip branch or master.