All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.pellse.reactive.assembler.kotlin.AssemblerKotlinSupport.kt Maven / Gradle / Ivy

/*
 * Copyright 2023 Sebastien Pelletier
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.pellse.reactive.assembler.kotlin

import io.github.pellse.reactive.assembler.AssemblerBuilder.WithCorrelationIdExtractorBuilder
import io.github.pellse.reactive.assembler.AssemblerBuilder.assemblerOf
import io.github.pellse.reactive.assembler.RuleMapper
import io.github.pellse.reactive.assembler.RuleMapper.oneToMany
import io.github.pellse.reactive.assembler.RuleMapper.oneToOne
import io.github.pellse.reactive.assembler.RuleMapperSource
import org.reactivestreams.Publisher
import reactor.core.publisher.Flux.fromIterable

inline fun  assembler(): WithCorrelationIdExtractorBuilder = assemblerOf(T::class.java)

fun , R> ((IDC) -> Iterable).toPublisher(): (IDC) -> Publisher = { ids -> fromIterable(this(ids)) }

fun , R> ((IDC) -> Publisher).oneToOne(defaultResultProvider: (ID) -> R): RuleMapper =
    oneToOne(this, defaultResultProvider)

fun , R> RuleMapperSource.oneToOne(defaultResultProvider: (ID) -> R): RuleMapper =
    oneToOne(this, defaultResultProvider)

fun , R> ((IDC) -> Publisher).oneToMany(idExtractor: (R) -> EID): RuleMapper> =
    oneToMany(idExtractor, this)

fun , R> RuleMapperSource>.oneToMany(idExtractor: (R) -> EID): RuleMapper> =
    oneToMany(idExtractor, this)

fun , R, RC : Collection> ((IDC) -> Publisher).oneToMany(idExtractor: (R) -> EID, collectionFactory: () -> RC): RuleMapper =
    oneToMany(idExtractor, this, collectionFactory)

fun , R, RC : Collection> RuleMapperSource.oneToMany(idExtractor: (R) -> EID, collectionFactory: () -> RC): RuleMapper =
    oneToMany(idExtractor, this, collectionFactory)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy