Reputation:
If I have a Traversable
instance, xs
, how do I convert it into a Vector
?
Upvotes: 10
Views: 454
Reputation: 10783
All Traversable
instances are also Foldable
, so you can write something like
toVector :: Foldable t => t a -> Vector a
toVector = Vector.fromList . Foldable.toList
{-# INLINE toVector #-}
This might make an intermediate list though, if that doesn't get fused away. The inlining should help make fusion more likely.
Upvotes: 11