Skip to content
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

Make cats.effect.std.PQueue share cats.effect.std.Queue trait #3721

Closed
skedlukecollier opened this issue Jun 28, 2023 · 7 comments
Closed

Make cats.effect.std.PQueue share cats.effect.std.Queue trait #3721

skedlukecollier opened this issue Jun 28, 2023 · 7 comments
Assignees

Comments

@skedlukecollier
Copy link

Currently PQueue extends PQueueSource and PQueueSink ran into a problem where trying to use fs2.Stream#fromQueueUnterminating led to a type error on a PQueue so following a convo on discord the trait's be linked or unified

@skedlukecollier skedlukecollier changed the title Make cats.effect.std.PQueue extend cats.effect.std.Queue Make cats.effect.std.PQueue share cats.effect.std.Queue trait Jun 28, 2023
@armanbilge
Copy link
Member

Sorry, now that I think about it: I can see an argument that PQueue should not extend/implement the Queue trait, depending on what the Queue trait is promising. For example, if it is promising FIFO, then passing a PQueue could observably violate that expectation.

However, QueueSink and QueueSource specifically don't offer sufficient API surface to assert these sorts of laws. So in that case, it wouldn't seem unreasonable for PQueue{Source,SInk} to extend Queue{Source,Sink}. Their APIs are identical, both in terms of methods and semantics.

Actually, this makes me wonder if a better hierarchy might have been QueueSource, QueueSink, and Queue, with marker interfaces FifoQueue and PQueue. Then calling code could declare precisely what it does or doesn't need to work correctly.

Thoughts?

@skedlukecollier
Copy link
Author

For the specific problem I had I think extending PQueueSource and PQueueSink with the QueueSink and QueueSource seems like the solution we're after!

For the next part would the Queue remain as is, then PQueue and a new FifoQueue extend Queue?

If I'm following then it would give types hints for these types of questions that Java faces due to its shared queue interface.

For me, the difference between a PQueue and Queue seems like a happy level of detail for most use cases here, 9/10 a Queue is probably fifo.

@armanbilge
Copy link
Member

For the specific problem I had I think extending PQueueSource and PQueueSink with the QueueSink and QueueSource seems like the solution we're after!

Yes, I think so too! I think we can definitely make this change.

For the next part would the Queue remain as is, then PQueue and a new FifoQueue extend Queue?

Well, ideally we'd do this, but due to compatibility constraints we probably no longer can. i.e. the expectation is that Queue is a FIFO queue, so actually we need to add something "above" it in the hierarchy which may not be FIFO.

@skedlukecollier
Copy link
Author

Yes, I think so too! I think we can definitely make this change.

Created #3733 for this, will update it to not be failing when I get chance

Well, ideally we'd do this, but due to compatibility constraints we probably no longer can. i.e. the expectation is that Queue is a FIFO queue, so actually we need to add something "above" it in the hierarchy which may not be FIFO.

I can't think of a word for an AbstractQueue perhaps that's a sign it's an unnecessary abstraction? 🤔

@armanbilge
Copy link
Member

it's an unnecessary abstraction

true, at the moment we don't have a usecase for it.

@neomaclin
Copy link
Contributor

neomaclin commented Jan 5, 2024

added a PR #3930 to follow up on this

@durban
Copy link
Contributor

durban commented Feb 7, 2024

Fixed by #3930.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants