Closed ngua closed 3 years ago
I intentionally didn't add pattern synonyms for viewing the front/back, since viewl
/viewr
and <|
/|>
don't run in truly constant time (as opposed to the Data.Sequence
counterparts). This could lead to confusion, when people expect pattern matching to have negligible cost. As an alternative, you could use the ViewPatterns
extension, for example:
updateHead :: (a -> a) -> Vector a -> Vector a
updateHead f (viewl -> Just (x, xs)) = f x <| xs
updateHead _ xs = xs
updateLast :: (a -> a) -> Vector a -> Vector a
updateLast f (viewr -> Just (xs, x)) = xs |> f x
updateLast _ xs = xs
However, if you're mostly using the Seq
s as queue/deque (i.e. you're mostly using viewl
/viewr
and <|
/|>
), I don't recommend switching, my Vector
will likely be slower. Feel free to share your experience with replacing Seq
by Vector
though!
Ah, I see, that makes a lot of sense. ViewPatterns
are a great alternative, though, thanks for the suggestion. Anyway, I'll go ahead and close this now. Thanks again!
Hi, @konsumlamm, thanks for publishing
rrb-vector
. I'd like to try it out as a replacement forSeq
s in a few projects I'm working on. When working withSeq
s, I find using the bundled pattern synonyms quite convenient. Would you be interested in adding similar pattern synonyms forVector
(I didn't see any in the haddocks)? If you think it might be a good choice, I could try to implement them and open a PR. Thanks!