simon.vergauwen
02/28/2018, 3:10 PMfun T?.xxx
it becomes available everywhere because T?
could be anything even another data type,tginiotis
02/28/2018, 3:13 PMraulraja
02/28/2018, 4:38 PMimport arrow.syntax.nullable.*
The biggest issue I see is that it requires a wrapper since we would not be able to define a Kind
for nullables easily. But most combinators can be expressed:
fun <A> A.pureNullable(): A? = this
fun <A, B> A?.map(f: (A) -> B): B? =
this?.let(f)
fun <A, B> A?.flatMap(f: (A) -> B?): B? =
this?.let(f)
fun <A> A?.empty(): Boolean = this != null
fun <A, R> A?.fold(ifNull: () -> R, ifNotNull: (A) -> R): R =
if (this == null) ifNull() else ifNotNull(this)
fun <A, B> A?.ap(ff: ((A) -> B)?): B? =
ff.flatMap { this.map(it) }
fun <A> A?.filter(predicate: (A) -> Boolean): A? =
if (this == null) this
else if (predicate(this)) this
else null
simon.vergauwen
02/28/2018, 4:47 PMimport arrow.syntax.nullable.*
like so it might work indeed. In am thinking about our old package structure.