sizovs / PipelinR

PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your Java awesome app.
https://github.com/sizovs/PipelinR
MIT License
420 stars 59 forks source link

Problem with Kotlin Generics. #15

Closed aliwassouf closed 3 years ago

aliwassouf commented 3 years ago

I am following the example of the readme file you guys have (Ping command, Pong handler) but I am using Kotlin.

I have the following code

class Ping(val host: String) : Command<String>
class Pong : Command.Handler<Ping, String>{

    override fun handle(command: Ping): String {
        return "Pong from " + command.host;
    }

}

Now when trying this code

    var pipeline: Pipeline = Pipelinr().with { Stream.of(Pong()) }

It doesn't compile I get this error:

Overload resolution ambiguity. All these functions match.

- public final fun with(notificationHandlingStrategySupplier: (() → NotificationHandlingStrategy!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr

- public final fun with(commandHandlers: (() → Stream<(an.awesome.pipelinr.Command.Handler<Command<*>!, Any!>..an.awesome.pipelinr.Command.Handler<out Command<*>!, *>?)>!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr

- public final fun with(middlewares: (() → Stream<an.awesome.pipelinr.Command.Middleware!>!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr

- public final fun with(notificationHandlers: (() → Stream<(an.awesome.pipelinr.Notification.Handler<Notification!>..an.awesome.pipelinr.Notification.Handler<*>?)>!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr

- public final fun with(middlewares: (() → Stream<an.awesome.pipelinr.Notification.Middleware!>!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr
- public final fun with(steps: (() → Stream<PipelineStep!>!)!): Pipelinr! defined in an.awesome.pipelinr.Pipelinr
sizovs commented 3 years ago

Hey @aliwassouf

Thanks for reporting this and sorry for the late response. Here is how you configure PipelinR in Kotlin:


class Ping(val host: String) : Command<String>

class Pong : Handler<Ping, String>{
  override fun handle(command: Ping): String {
    return "Pong from ${command.host}"
  }
}

val handlers = CommandHandlers {
  Stream.of(Pong())
}

val pipeline = Pipelinr().with(handlers)

Did it solve your problem?

aliwassouf commented 3 years ago

@sizovs Thanks My friend @lucasls suggested this solution as well. And yes it solved my problem Thanks to you both.

sizovs commented 3 years ago

Great! I am closing the issue then.

lucasls commented 3 years ago

I'm not yet very familiarized with PipelinR, but I would assume at some of these methods could be extended with Kotlin Extension Functions in order to provide a more Kotlin idiomatic API. Perhaps @aliwassouf and I could try creating those on demand, and depending on our results, contribute back to the project?

sizovs commented 3 years ago

@lucasls @aliwassouf if it will make PipelinR more usable in Kotlin, why not giving it a try? I am curious to see what you folks come up with.

gustavodaquino commented 3 years ago

How can I adapt the Bean Configurationin a SpringBoot project with Kotlin?

sizovs commented 3 years ago

How can I adapt the Bean Configurationin a SpringBoot project with Kotlin?

Hei @gustavodaquino. Because the question is not related to this thread, could you please create a separate issue for it, and provide a specific example?