Reimplement .toArray using .collect

As per the (now deleted) TODO comment.