-
Notifications
You must be signed in to change notification settings - Fork 70
Add intersperse with tests #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add intersperse with tests #188
Conversation
Can I get a review here? |
src/Data/Array.purs
Outdated
-- | ``` | ||
-- | | ||
-- | If the array has one or zero elements, the resulting array is a copy | ||
-- | of the input array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to use copy since it's not technically the "same" array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually will be the same array with this implementation. If you mutate one, you’ll see that change reflected in the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... Shoot, that's right. Let me fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in latest commits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous implementation was preferable - there's no reason to make a copy here, since Array
is already immutable. You'd have to use an escape hatch like unsafeThaw
or the FFI to mutate an Array
, but that's not something we need to defend against, because it can only happen through misuse of said escape hatches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
Latest commit reverts that change
This doesn't work currently, but it's forward-compatible when we do implement syntax highlighting
CI builds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving because I think this is good to merge once these comments have been addressed. Thanks! 👍
src/Data/Array.purs
Outdated
-- | intersperse 0 [ 1, 2, 3, 4, 5 ] == [ 1, 0, 2, 0, 3, 0, 4, 0, 5 ] | ||
-- | ``` | ||
-- | | ||
-- | If the array has one or zero elements, the input array is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "less than two" might read a bit more naturally here? Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I think I could go either way.
Meh, let's just use the "less than two."
src/Data/Array.purs
Outdated
let unsafeGetElem idx = unsafePartial (unsafeIndex arr idx) | ||
out <- STA.empty | ||
_ <- STA.push (unsafeGetElem 0) out | ||
STI.for 1 len \idx -> do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for
is re-exported from Control.Monad.ST
, so I don't think we need to import the Internal module here (and if we can avoid importing the Internal module, it would be good to do that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Good catch! Fixed in latest commits.
Fixes #15