Added `flatten` and `flatten(x)` functions

Fix #415.