Skip to content

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

Merged
merged 7 commits into from
Dec 16, 2020
Merged

Add intersperse with tests #188

merged 7 commits into from
Dec 16, 2020

Conversation

JordanMartinez
Copy link
Contributor

Fixes #15

@JordanMartinez
Copy link
Contributor Author

Can I get a review here?

-- | ```
-- |
-- | If the array has one or zero elements, the resulting array is a copy
-- | of the input array.
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest commits

Copy link
Contributor

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.

Copy link
Contributor Author

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

@JordanMartinez
Copy link
Contributor Author

CI builds.

Copy link
Contributor

@hdgarrood hdgarrood left a 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! 👍

-- | 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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."

let unsafeGetElem idx = unsafePartial (unsafeIndex arr idx)
out <- STA.empty
_ <- STA.push (unsafeGetElem 0) out
STI.for 1 len \idx -> do
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@thomashoneyman thomashoneyman merged commit 131a232 into purescript:master Dec 16, 2020
@JordanMartinez JordanMartinez deleted the addIntercalate branch December 16, 2020 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

intersperse
3 participants