By defining functions like `fun T?.xxx` it becomes...
# arrow
s
By defining functions like
fun T?.xxx
it becomes available everywhere because
T?
could be anything even another data type,
t
ok, thanks for pointing that out
r
@simon.vergauwen what would be the collisions of that happening? it would only apply when the extension functions are imported in scope for example:
Copy code
import 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:
Copy code
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
s
import arrow.syntax.nullable.*
like so it might work indeed. In am thinking about our old package structure.
👍 2