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

Support for WithContext structure promotion added to Context.Companion #473

Merged
merged 1 commit into from
Dec 16, 2020

Conversation

oskin1
Copy link
Collaborator

@oskin1 oskin1 commented Dec 5, 2020

No description provided.

@oskin1 oskin1 changed the title Support for WithContext structure promotion added to `Context.Compa… Support for WithContext structure promotion added to Context.Companion Dec 5, 2020
type Has[F[_]] = WithContext[F, C]

implicit def tofuPromoteContextStructure[F[_], A](implicit
implicit def promoteContextStructure[F[_], A](implicit
Copy link
Member

Choose a reason for hiding this comment

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

I think the priorities are wrong. WithLocal as a more concrete instance should be higher, and WithContext - lower.

Can you write a summon test?

type Has[F[_]] = WithContext[F, C]

implicit def tofuPromoteContextStructure[F[_], A](implicit
abstract class WithContextOpaque[F[_], C0] extends WithContext[F, C0]
Copy link
Member

Choose a reason for hiding this comment

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

Why did you make it an inner class? It could be a concrete high-level class, as we usually do in tofu:

class WithContextContains[F[_], C, A](implicit wc: WithContext[F, C],  field: C Contains A)
  extends WithContext[F, A] {
  private val wa =  wc.extract(field) 
  def functor: Functor[F] = wa.functor
  def context: F[A]       = wa.context
}

And then in trait.

implicit def promoteContextStructure[F[_], A](implicit withContext: WithContext[F, C],
    field: C Contains A
): WithContextContains[F, C, A] =
    new WithContextContains[F, C, A]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@catostrophe, my bad, we'd better keep style consistent.

@Odomontois Odomontois merged commit 805ff28 into master Dec 16, 2020
@Odomontois Odomontois deleted the context-companion branch March 3, 2021 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants