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

Add utility types for fromHandlers and friends #1612

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Thank you!
# 0.18.26

* Optimises the conversion of empty smithy4s.Blob to fs2.Stream, to avoid performance degradation in Ember (see [#1609](https://github.com/disneystreaming/smithy4s/pull/1609))
* Adds utility types for working with endpoint handlers (see [#1612](https://github.com/disneystreaming/smithy4s/pull/1612))

# 0.18.25

Expand Down
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