Skip to content

Commit

Permalink
refactor: mark conversion functions suspending
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Jun 30, 2023
1 parent 162ad96 commit 171c8ed
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions exkt-dto/src/commonMain/kotlin/dev/d1s/exkt/dto/DtoConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface DtoConverter<TEntity : Any, TDto : Any> {
* @see convertToDtoList
* @see convertToDtoListIf
*/
public fun convertToDto(entity: TEntity): TDto {
public suspend fun convertToDto(entity: TEntity): TDto {
throw NotImplementedError()
}

Expand All @@ -46,15 +46,15 @@ public interface DtoConverter<TEntity : Any, TDto : Any> {
*
* @see convertToEntities
*/
public fun convertToEntity(dto: TDto): TEntity {
public suspend fun convertToEntity(dto: TDto): TEntity {
throw NotImplementedError()
}
}

/**
* Converts given [entity] to [DTO][TDto] if the given [predicate] matches. Returns `null` otherwise.
*/
public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoIf(
public suspend fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoIf(
entity: TEntity,
predicate: () -> Boolean
): TDto? =
Expand All @@ -67,15 +67,15 @@ public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoI
/**
* Converts given [entities] to [DTO list][List].
*/
public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoList(entities: List<TEntity>): List<TDto> =
public suspend fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoList(entities: List<TEntity>): List<TDto> =
entities.map {
convertToDto(it)
}

/**
* Converts given [entities] to [DTO list][List] if the given [predicate] matches. Returns `null` otherwise.
*/
public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoListIf(
public suspend fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoListIf(
entities: List<TEntity>,
predicate: () -> Boolean
): List<TDto>? =
Expand All @@ -88,7 +88,7 @@ public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToDtoL
/**
* Converts given [DTO list][dtoList] to [entities][List].
*/
public fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToEntities(dtoList: List<TDto>): List<TEntity> =
public suspend fun <TEntity : Any, TDto : Any> DtoConverter<TEntity, TDto>.convertToEntities(dtoList: List<TDto>): List<TEntity> =
dtoList.map {
convertToEntity(it)
}

0 comments on commit 171c8ed

Please sign in to comment.