Skip to content

Commit

Permalink
Add utility types for fromHandlers and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 18, 2024
1 parent ec140e5 commit 36d5902
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/core/src/smithy4s/Service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ trait Service[Alg[_[_, _, _, _, _]]] extends FunctorK5[Alg] with HasId {
*/
type ErrorAware[F[_, _]] = BiFunctorAlgebra[Alg, F]

/* *
* A short-hand for the result of a MyService.fromFunctorHandlers call.
*/
type FromFunctorHandlers[F[_]] = EndpointHandler.AsService[Alg, Kind1[F]#toKind5]

/* *
* A short-hand for the result of a MyService.fromHandlers call.
*/
type FromHandlers[F[_, _, _, _, _]] = EndpointHandler.AsService[Alg, F]

val service: Service[Alg] = this
def endpoints: IndexedSeq[Endpoint[_, _, _, _, _]]

Expand Down Expand Up @@ -179,19 +189,19 @@ trait Service[Alg[_[_, _, _, _, _]]] extends FunctorK5[Alg] with HasId {
/**
* Allows to turn a list of endpoint handlers into an instance of [[Alg]].
*/
final def fromHandlers[F[_, _, _, _, _]](handlers: EndpointHandler[Operation, F]*): EndpointHandler.AsService[Alg, F] =
final def fromHandlers[F[_, _, _, _, _]](handlers: EndpointHandler[Operation, F]*): FromHandlers[F] =
EndpointHandler.combineAll(handlers:_*).asService(this)

/**
* A functor-specialised version of [[fromHandlers]], to help scala 2.12
*/
final def fromFunctorHandlers[F[_]](handlers: EndpointHandler[Operation, Kind1[F]#toKind5]*) : EndpointHandler.AsService[Alg, Kind1[F]#toKind5]
final def fromFunctorHandlers[F[_]](handlers: EndpointHandler[Operation, Kind1[F]#toKind5]*): FromFunctorHandlers[F]
= fromHandlers[Kind1[F]#toKind5](handlers:_*)

/**
* A bifunctor-specialised version of [[fromHandlers]], to help scala 2.12
*/
final def fromBifunctorHandlers[F[_, _]](handlers: EndpointHandler[Operation, Kind2[F]#toKind5]*) : EndpointHandler.AsService[Alg, Kind2[F]#toKind5]
final def fromBifunctorHandlers[F[_, _]](handlers: EndpointHandler[Operation, Kind2[F]#toKind5]*) : FromHandlers[Kind2[F]#toKind5]
= fromHandlers[Kind2[F]#toKind5](handlers:_*)
}

Expand Down

0 comments on commit 36d5902

Please sign in to comment.