Skip to content

Commit

Permalink
Add MediaListFilter.or
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Sep 28, 2024
1 parent f09f431 commit f65cb06
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.data.source.media.source

import me.him188.ani.datasources.api.Media
Expand Down Expand Up @@ -38,6 +47,13 @@ fun interface MediaListFilter<in Ctx : MediaListFilterContext> {
fun Ctx.applyOn(media: Candidate): Boolean
}

infix fun <C : MediaListFilterContext> MediaListFilter<C>.or(cond: MediaListFilter<C>): MediaListFilter<C> {
val self = this
return MediaListFilter<C> { candidate ->
with(self) { applyOn(candidate) } || with(cond) { applyOn(candidate) }
}
}

typealias BasicMediaListFilter = MediaListFilter<MediaListFilterContext>

// TODO: require context MediaListFilterContext to limit scope
Expand Down

0 comments on commit f65cb06

Please sign in to comment.