Skip to content

Commit

Permalink
Rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Mar 19, 2019
1 parent f22262f commit cf63b61
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions doc/server/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ which you'd like to apply to an endpoint with type:
val myEndpoint: Endpoint[(AuthToken, String, Int), ErrorInfo, Result, Nothing] = ...
```

To avoid composing these functions by hand, tapir defines a helper extension method, `composeRight`. If the first
To avoid composing these functions by hand, tapir defines a helper extension method, `andThenRight`. If the first
function returns an error, that error is propagated to the final result; otherwise, the result is passed as input to
the second function.

Expand All @@ -60,15 +60,15 @@ interpreter) and for an arbitrary monad (in the http4s interpreter), so importin

```scala
import tapir.server.akkahttp._
val r: Route = myEndpoint.toRoute((authFn _).composeRight(logicFn _))
val r: Route = myEndpoint.toRoute((authFn _).andThenRight(logicFn _))
```

Writing down the types, here are the generic signatures when using `composeRight`:
Writing down the types, here are the generic signatures when using `andThenRight`:

```scala
f1: T => Future[Either[E, U]]
f2: (U, A1, A2, ...) => Future[Either[E, O]]
(f1 _).composeRight(f2): (T, A1, A2, ...) => Future[Either[E, O]]
(f1 _).andThenRight(f2): (T, A1, A2, ...) => Future[Either[E, O]]
```

## Exception handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait AkkaHttpServer {
}

implicit class RichToFutureFunction[T, E, U](f: T => Future[Either[E, U]])(implicit ec: ExecutionContext) {
def composeRight[O, FN_U[_], FN_T[_]](g: FN_U[Future[Either[E, O]]])(
def andThenRight[O, FN_U[_], FN_T[_]](g: FN_U[Future[Either[E, O]]])(
implicit
r: ReplaceFirstInFn[U, FN_U, T, FN_T]): FN_T[Future[Either[E, O]]] = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RichToFutureFunctionTest extends FunSuite with Matchers with ScalaFutures
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").futureValue
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").futureValue

// then
result shouldBe Right(Result("User(john),10,x"))
Expand All @@ -38,7 +38,7 @@ class RichToFutureFunctionTest extends FunSuite with Matchers with ScalaFutures
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").futureValue
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").futureValue

// then
result shouldBe Left(Error("e1"))
Expand All @@ -54,7 +54,7 @@ class RichToFutureFunctionTest extends FunSuite with Matchers with ScalaFutures
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").futureValue
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").futureValue

// then
result shouldBe Left(Error("e2"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait Http4sServer {
}

implicit class RichToMonadFunction[T, E, U, F[_]: Monad](f: T => F[Either[E, U]]) {
def composeRight[O, FN_U[_], FN_T[_]](g: FN_U[F[Either[E, O]]])(implicit
def andThenRight[O, FN_U[_], FN_T[_]](g: FN_U[F[Either[E, O]]])(implicit
r: ReplaceFirstInFn[U, FN_U, T, FN_T]): FN_T[F[Either[E, O]]] = {

r.paramsAsArgsJk.toFn { paramsWithT =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RichToMonadFunctionTest extends FunSuite with Matchers {
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").unsafeRunSync()
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").unsafeRunSync()

// then
result shouldBe Right(Result("User(john),10,x"))
Expand All @@ -35,7 +35,7 @@ class RichToMonadFunctionTest extends FunSuite with Matchers {
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").unsafeRunSync()
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").unsafeRunSync()

// then
result shouldBe Left(Error("e1"))
Expand All @@ -51,7 +51,7 @@ class RichToMonadFunctionTest extends FunSuite with Matchers {
}

// when
val result = (f1 _).composeRight(f2 _).apply("john", 10, "x").unsafeRunSync()
val result = (f1 _).andThenRight(f2 _).apply("john", 10, "x").unsafeRunSync()

// then
result shouldBe Left(Error("e2"))
Expand Down

0 comments on commit cf63b61

Please sign in to comment.