All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hireproof.structure.ContextProvider.scala Maven / Gradle / Ivy

The newest version!
package io.hireproof.structure

abstract class UnauthorizedContextProvider[F[_], Context[_[_], _]] {
  def implementedBy[I, O](endpoint: Endpoint[I, O])(f: Context[F, I] => F[O]): Endpoint.Implementation[F, I, O]
}

abstract class AuthorizedContextProvider[F[_], Context[_[_], _], T] {
  def implementedBy[I, O](endpoint: Endpoint.Authorized[T, I, O])(
      f: Context[F, I] => F[O]
  ): Endpoint.Authorized.Implementation[F, T, I, O]
}

abstract class ContextProvider[F[_], UnauthorizedContext[_[_], _], AuthorizedContext[_[_], _], T] {
  def unauthorized: UnauthorizedContextProvider[F, UnauthorizedContext]

  def authorized: AuthorizedContextProvider[F, AuthorizedContext, T]
}

object ContextProvider {
  def apply[F[_], UnauthorizedContext[_[_], _], AuthorizedContext[_[_], _], T](
      unauthorizedContextProvider: UnauthorizedContextProvider[F, UnauthorizedContext],
      authorizedContextProvider: AuthorizedContextProvider[F, AuthorizedContext, T]
  ): ContextProvider[F, UnauthorizedContext, AuthorizedContext, T] =
    new ContextProvider[F, UnauthorizedContext, AuthorizedContext, T] {
      override def unauthorized: UnauthorizedContextProvider[F, UnauthorizedContext] =
        unauthorizedContextProvider

      override def authorized: AuthorizedContextProvider[F, AuthorizedContext, T] = authorizedContextProvider
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy