Skip to content

Commit e87dea1

Browse files
committed
Utility functions for MaybeThreadChannels implementations
Not too sure of those methods names though
1 parent 122c43d commit e87dea1

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

core/src/commonMain/kotlin/entity/channel/thread/DeletedThreadChannel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public class DeletedThreadChannel(
1010
public override val kord: Kord,
1111
override val supplier: EntitySupplier = kord.defaultSupplier
1212
) : MaybeThreadChannel {
13+
override fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T> {
14+
return Result.failure(Exception("The thread does not exists anymore."))
15+
}
16+
17+
override fun <T> doIfStillExist(func: () -> T) {
18+
return;
19+
}
20+
1321
override fun withStrategy(strategy: EntitySupplyStrategy<*>): DeletedThreadChannel {
1422
return DeletedThreadChannel(data, kord, strategy.supply(kord))
1523
}

core/src/commonMain/kotlin/entity/channel/thread/MaybeThreadChannel.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ public sealed interface MaybeThreadChannel : Strategizable {
5858
* @throws [RequestException] if something went wrong during the request.
5959
*/
6060
public suspend fun getParentOrNull(): ThreadParentChannel? = supplier.getChannelOfOrNull(parentId)
61+
62+
/**
63+
* Return the value of the function in parameter if the thread is not deleted.
64+
*
65+
* MIGHT FAIL!
66+
*/
67+
public fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T>
68+
69+
/**
70+
* Execute the function in parameter if the thread is not deleted.
71+
*/
72+
public fun <T> doIfStillExist(func: () -> T): Unit
6173
}

core/src/commonMain/kotlin/entity/channel/thread/ThreadChannel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ public interface ThreadChannel : GuildMessageChannel, ThreadChannelBehavior, May
131131
*/
132132
public val appliedTags: List<Snowflake> get() = data.appliedTags.value ?: emptyList()
133133

134+
override fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T> = Result.success(func())
135+
136+
override fun <T> doIfStillExist(func: () -> T) {
137+
func()
138+
}
139+
134140
override fun withStrategy(strategy: EntitySupplyStrategy<*>): ThreadChannel {
135141
return ThreadChannel(data, kord, strategy.supply(kord))
136142
}

0 commit comments

Comments
 (0)