From 2b8a1369627faf6f13a5b08719453c816757c7f7 Mon Sep 17 00:00:00 2001 From: Florian Kirmaier Date: Fri, 15 Dec 2023 12:54:58 +0100 Subject: [PATCH] Fixing route.when (#20) --- CHANGELOG.md | 5 +++++ .../main/scala/one/jpro/platform/routing/Route.scala | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc57fddc..539a78ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +### 0.2.8 +#### Changes +* Fixed parts of the `Route.when` api, which had unexpected argument types. + ### 0.2.7 (December 8, 2023) #### Improvements diff --git a/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Route.scala b/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Route.scala index be08463a..5cca9da9 100644 --- a/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Route.scala +++ b/jpro-routing/core/src/main/scala/one/jpro/platform/routing/Route.scala @@ -64,10 +64,15 @@ trait Route { val r2: FXFuture[Response] = if(condResult) _then(r) else null r2 }) - def when(cond: java.util.function.Function[Request, FXFuture[java.lang.Boolean]], _then: Response): Route = and(r => { - cond.apply(r).map(condResult => if(condResult) _then else null) - }) def when(cond: Predicate[Request], _then: Route, _else: Route): Route = and(r => { if(cond.test(r)) _then(r) else _else(r) }) + + def when(cond: java.util.function.Function[Request, FXFuture[java.lang.Boolean]], _then: Route): Route = and(r => { + cond.apply(r).flatMap(condResult => if (condResult) _then(r) else null) + }) + + def when(cond: java.util.function.Function[Request, FXFuture[java.lang.Boolean]], _then: Route, _else: Route): Route = and(r => { + cond.apply(r).flatMap(condResult => if (condResult) _then(r) else _else(r)) + }) }