Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Boru is a pipeline solution

License

NotificationsYou must be signed in to change notification settings

Trendyol/boru

Repository files navigation

boru

boru is a pipeline implementation in kotlin with native coroutine support and custom dsl.

Supports chaining pipeline steps with conditions and branches.

Inspired by@oguzhaneren's C# implementation

<dependency>    <groupId>com.trendyol</groupId>    <artifactId>boru</artifactId>    <version>1.0.0</version></dependency>

USAGE

Defining Context

Define a context implementing PipelineContext. In this case a simple context that sets and gets a text field

interfacePipelineContext {val items:Map<Any,Any>}classTestDataContext :PipelineContext {overrideval items:MutableMap<Any,Any>=mutableMapOf()var intValue:Int=0var text:String?        get()= items.getOrDefault("Text",null).toString()        set(value) {            items["Text"]= value!!        }}

Define Pipeline Steps

Implement a pipeline step using TestDataContext

classTestWriterStep(privatevaltext:String,) : PipelineStep<TestDataContext> {overridesuspendfunexecute(context:TestDataContext,next:PipelineStepDelegate<TestDataContext>) {        context.text= text        next(context)    }}

Build Pipeline

funcompose() {val pipeline=PipelineBuilder<TestDataContext>()        .usePipelineStep(TestWriterStep("hello"))        .build()val context=TestDataContext()}

You can also use lambda functions without defining a pipeline step

funcompose() {val pipeline=PipelineBuilder<TestDataContext>()        .use { context:TestDataContext, next:suspend ()->Unit->            context.text="hello"            next()        }        .build()val context=TestDataContext()}

Or use built-in dsl

funcompose() {val pipeline= pipelineBuilder<TestDataContext> {        use { testDataContext:TestDataContext, next:suspend ()->Unit->            context.text="Hello World"            next()        }    }}

Conditions and Branching

You can also use conditions when executing steps or branch using map operation

funcompose() {val pipeline= pipelineBuilder<TestDataContext> {        usePipelineStepWhen(TestWriterStep("Hello World")) {            it.text=="ExecuteStep"        }    }}

Mapping allows you to group multiple steps under one condition.

funcomposeMapping() {val pipeline= pipelineBuilder<TestDataContext> {        map({ it.intValue<3 }) {            usePipelineStep(TestWriterStep("one"))            usePipelineStep(TestWriterStep("two"))        }        map({ it.intValue==3 }) {            usePipelineStep(TestWriterStep("three"))        }    }}

Examples

You can check out otherexamples

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp