Add toFunction method for convenience
Add example to README