Package-level declarations

Types

Link copied to clipboard
object None
Link copied to clipboard
data class Single<out A>(val first: A)
Link copied to clipboard
typealias Tuple0 = None
Link copied to clipboard
typealias Tuple1<A> = Single<A>
Link copied to clipboard
typealias Tuple10<A, B, C, D, E, F, G, H, I, J> = arrow.core.Tuple10<A, B, C, D, E, F, G, H, I, J>
Link copied to clipboard
typealias Tuple2<A, B> = Pair<A, B>
Link copied to clipboard
typealias Tuple3<A, B, C> = Triple<A, B, C>
Link copied to clipboard
typealias Tuple4<A, B, C, D> = arrow.core.Tuple4<A, B, C, D>
Link copied to clipboard
typealias Tuple5<A, B, C, D, E> = arrow.core.Tuple5<A, B, C, D, E>
Link copied to clipboard
typealias Tuple6<A, B, C, D, E, F> = arrow.core.Tuple6<A, B, C, D, E, F>
Link copied to clipboard
typealias Tuple7<A, B, C, D, E, F, G> = arrow.core.Tuple7<A, B, C, D, E, F, G>
Link copied to clipboard
typealias Tuple8<A, B, C, D, E, F, G, H> = arrow.core.Tuple8<A, B, C, D, E, F, G, H>
Link copied to clipboard
typealias Tuple9<A, B, C, D, E, F, G, H, I> = arrow.core.Tuple9<A, B, C, D, E, F, G, H, I>
Link copied to clipboard
data class WrapBoolean<R>(val condition: Boolean, val result: R?)

一个kotlin实现的类似三元表达式,甚至由于语言的特性,可以用来返回函数:

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

仅数字+字母

Link copied to clipboard

仅数字

Link copied to clipboard
Link copied to clipboard

全局的空判断扩展属性,这样做空判断时更为优雅

Link copied to clipboard
const val TAG: String

Functions

Link copied to clipboard
Link copied to clipboard
fun Boolean?.asIs(default: Boolean = true): Boolean

可空布尔量的字面值,如果他是空则取默认值

Link copied to clipboard
fun Boolean?.asNot(default: Boolean = false): Boolean

可空布尔量字面值取反,如果为空则取默认值

Link copied to clipboard
fun Any?.ifTrue(): Any?

一个过滤判断赋值,可以用来过滤空数组、0 Duration、0、false字符串等等,将这些对象直接视为 null

Link copied to clipboard

验证是否邮箱

Link copied to clipboard

验证是否手机

Link copied to clipboard

验证是否电话

Link copied to clipboard

Description: 校验是否为合法文件名

Link copied to clipboard
fun Boolean?.not(default: Boolean = false): Boolean
Link copied to clipboard
fun String.padLeft(len: Int, ch: Char): String
Link copied to clipboard
fun String.padRight(len: Int, ch: Char): String
Link copied to clipboard
operator fun <A, B, C, D, E> Tuple4<A, B, C, D>.plus(e: E): Tuple5<A, B, C, D, E>
operator fun <A, B, C, D, E, F> Tuple5<A, B, C, D, E>.plus(f: F): Tuple6<A, B, C, D, E, F>
operator fun <A, B, C, D, E, F, G> Tuple6<A, B, C, D, E, F>.plus(g: G): Tuple7<A, B, C, D, E, F, G>
operator fun <A, B, C, D, E, F, G, H> Tuple7<A, B, C, D, E, F, G>.plus(h: H): Tuple8<A, B, C, D, E, F, G, H>
operator fun <A, B, C, D, E, F, G, H, I> Tuple8<A, B, C, D, E, F, G, H>.plus(i: I): Tuple9<A, B, C, D, E, F, G, H, I>
operator fun <A, B, C, D, E, F, G, H, I, J> Tuple9<A, B, C, D, E, F, G, H, I>.plus(j: J): Tuple10<A, B, C, D, E, F, G, H, I, J>
operator fun <A, B, C> Pair<A, B>.plus(c: C): Triple<A, B, C>
operator fun <A, B, C, D> Triple<A, B, C>.plus(d: D): Tuple4<A, B, C, D>
Link copied to clipboard
inline fun <T> printType(t: T): KType

打印泛型

Link copied to clipboard
inline fun <T, R> T.runIf(condition: Boolean = true, noinline block: T.() -> R): R?

效果等同于 if(){},条件达成执行闭包,它不同于if的是,它具有返回值,可以用于一些条件赋值、可空初始化,例如:

Link copied to clipboard
inline fun <T, R> T.runUnless(condition: Boolean = true, noinline block: T.() -> R): R?

与上面的效果相反,条件达成则不执行,条件为否定时执行闭包

Link copied to clipboard

字符串安全转换到双精度类型,转换失败返回0

Link copied to clipboard

字符串安全转换到整型,转换失败返回0

Link copied to clipboard

字符串安全转换到长整型,转换失败返回0

Link copied to clipboard

字符串安全转换到短整型类型,转换失败返回0

Link copied to clipboard
inline fun <T> Boolean.switches(noinline ifTrue: (Boolean) -> T, noinline ifFalse: (Boolean) -> T): T

一个简单的if-else能返回结果的实现,类似于Either的左右值,它可以更好的将代码变成链式函数调用, 也完全可以配合 arrow-kt,将结果封装成Either

Link copied to clipboard
inline fun <T> T.then(block: (T) -> Unit)

一个返回Unit的扩展函数,只保障闭包执行,可以看成是无返回值的 let 函数, 在一些需要函数返回值的场景可以用来替代显式书写的Unit

Link copied to clipboard
infix fun <A, B, C, D, E> Tuple4<A, B, C, D>.to(e: E): Tuple5<A, B, C, D, E>
infix fun <A, B, C, D, E, F> Tuple5<A, B, C, D, E>.to(f: F): Tuple6<A, B, C, D, E, F>
infix fun <A, B, C, D, E, F, G> Tuple6<A, B, C, D, E, F>.to(g: G): Tuple7<A, B, C, D, E, F, G>
infix fun <A, B, C, D, E, F, G, H> Tuple7<A, B, C, D, E, F, G>.to(h: H): Tuple8<A, B, C, D, E, F, G, H>
infix fun <A, B, C, D, E, F, G, H, I> Tuple8<A, B, C, D, E, F, G, H>.to(i: I): Tuple9<A, B, C, D, E, F, G, H, I>
infix fun <A, B, C, D, E, F, G, H, I, J> Tuple9<A, B, C, D, E, F, G, H, I>.to(j: J): Tuple10<A, B, C, D, E, F, G, H, I, J>
infix fun <A, B, C> Pair<A, B>.to(c: C): Triple<A, B, C>
infix fun <A, B, C, D> Triple<A, B, C>.to(d: D): Tuple4<A, B, C, D>

infix fun <A, B> Single<A>.to(b: B): Pair<A, B>

元组扩展,可以使用 a to b to c 这样的连续中缀函数创建更多元素的元组

Link copied to clipboard
fun toBoolean(value: Any?): Boolean

将任意值转换成布尔,类似JS的 Boolean包装器函数

Link copied to clipboard
fun <T> Tuple10<T, T, T, T, T, T, T, T, T, T>.toList(): List<T>
fun <T> Tuple4<T, T, T, T>.toList(): List<T>
fun <T> Tuple5<T, T, T, T, T>.toList(): List<T>
fun <T> Tuple6<T, T, T, T, T, T>.toList(): List<T>
fun <T> Tuple7<T, T, T, T, T, T, T>.toList(): List<T>
fun <T> Tuple8<T, T, T, T, T, T, T, T>.toList(): List<T>
fun <T> Tuple9<T, T, T, T, T, T, T, T, T>.toList(): List<T>
fun <T> None.toList(): List<T>
fun <T> Single<T>.toList(): List<T>
Link copied to clipboard
fun tuple(): None
fun <A> tuple(first: A): Tuple1<A>
fun <A, B> tuple(first: A, second: B): Tuple2<A, B>
fun <A, B, C> tuple(first: A, second: B, third: C): Tuple3<A, B, C>
fun <A, B, C, D> tuple(first: A, second: B, third: C, fourth: D): Tuple4<A, B, C, D>
fun <A, B, C, D, E> tuple(first: A, second: B, third: C, fourth: D, fifth: E): Tuple5<A, B, C, D, E>
fun <A, B, C, D, E, F> tuple(first: A, second: B, third: C, fourth: D, fifth: E, sixth: F): Tuple6<A, B, C, D, E, F>
fun <A, B, C, D, E, F, G> tuple(first: A, second: B, third: C, fourth: D, fifth: E, sixth: F, seventh: G): Tuple7<A, B, C, D, E, F, G>
fun <A, B, C, D, E, F, G, H> tuple(first: A, second: B, third: C, fourth: D, fifth: E, sixth: F, seventh: G, eighth: H): Tuple8<A, B, C, D, E, F, G, H>
fun <A, B, C, D, E, F, G, H, I> tuple(first: A, second: B, third: C, fourth: D, fifth: E, sixth: F, seventh: G, eighth: H, ninth: I): Tuple9<A, B, C, D, E, F, G, H, I>
fun <A, B, C, D, E, F, G, H, I, J> tuple(first: A, second: B, third: C, fourth: D, fifth: E, sixth: F, seventh: G, eighth: H, ninth: I, tenth: J): Tuple10<A, B, C, D, E, F, G, H, I, J>
Link copied to clipboard
infix inline fun <R> WrapBoolean<R>.(ifFalse: R?): R?
Link copied to clipboard
infix inline fun <R> Boolean.(ifTrue: R?): WrapBoolean<R>