Refactor -toArray using -collect and -first

And because collectedValues is mutable, return immutable object using -copy.
Add a test for -collect handling nil values
Add tests for -toArray
Merge pull request #498 from ikesyo/refactor-toarray

Refactor -toArray using -collect and -first