Skip to content

Conversation

@shardulc
Copy link
Contributor

No description provided.

@SethTisue
Copy link
Collaborator

I put a call for reviewers on Discord — let's merge in 24 hours unless there is unresolved review feedback at that point

Copy link
Collaborator

@SethTisue SethTisue left a comment

Choose a reason for hiding this comment

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

(none of this is terribly important, but just some thoughts)

input.flatMap(_.map(Direction.ofChar)).toSeq

def parse(inputFile: String): (Warehouse, Seq[Direction]) =
val file = io.Source.fromFile(inputFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe Using instead of try/finally? I don't have a strong opinion here, just wondering if you'd considered it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it more idiomatic? I'd have to look up how to use it 😅 but I could

Copy link

@twentylemon twentylemon left a comment

Choose a reason for hiding this comment

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

Hello, I am a random person from said discord. 🫡

LGTM, clean solution! 🚀

Comment on lines +156 to +162
val newCells = cells.map(_.toArray).toArray
// mutate it,
updates.foreach{ case ((row, col), cell) => newCells(row)(col) = cell }
// and construct a new ArraySeq backed by it. Possibly unsafe if the
// backing array remains accessible outside of the ArraySeq, but safe
// here because the method only returns the ArraySeq.
ArraySeq.unsafeWrapArray(newCells).map(ArraySeq.unsafeWrapArray)

Choose a reason for hiding this comment

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

Minor, might be able to avoid these unsafes by using Seq everywhere instead of the ArraySeq implementation type, and using .toSeq instead of the .toArrays. Seq is still immutable, so it won't compromise your morals!

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 but I know the size ahead of time and I know I will be doing a lot of random accesses. Seq doesn’t guarantee anything about that, right? (I’ll add this to my reasoning note)

Choose a reason for hiding this comment

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

Yeah, but the typical implementation of Seq is the Vector, which offers basically O(1) everything. See docs.

Copy link
Collaborator

@SethTisue SethTisue Dec 22, 2024

Choose a reason for hiding this comment

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

the default implementation of Seq is List, but .toIndexedSeq is worth considering (not sure what my opinion is). I think most of us tend to forget that .toIndexedSeq even exists (I forgot, until I suddenly remembered).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My personal approach is to not rely on what the typical/default implementation is, but rather to only assume what the docs guarantee, and Seq and IndexedSeq would not quite guarantee enough. I would also have thought that Vectors provide O(1) random access but the Scala 3 docs say it's O(log n).

Copy link
Collaborator

Choose a reason for hiding this comment

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

(The collections guide calls that "effectively constant" since the base of the log is quite high, so that it can never take more than a small number of steps.)

@shardulc shardulc requested a review from SethTisue December 21, 2024 09:36
@SethTisue SethTisue merged commit 87122ae into scalacenter:website Dec 21, 2024
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.

3 participants