-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Arrow-kt dependency #7335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dependency to arrow has been removed. Please use `org.matrix.android.sdk.api.util.Optional` instead. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,13 @@ | |
*/ | ||
package org.matrix.android.sdk.api.util | ||
|
||
data class Optional<T : Any> constructor(private val value: T?) { | ||
data class Optional<T : Any>(private val value: T?) { | ||
|
||
fun get(): T { | ||
return value!! | ||
} | ||
fun get(): T = value!! | ||
|
||
fun getOrNull(): T? { | ||
return value | ||
} | ||
fun orNull(): T? = value | ||
|
||
fun getOrNull(): T? = value | ||
|
||
fun <U : Any> map(fn: (T) -> U?): Optional<U> { | ||
return if (value == null) { | ||
|
@@ -33,23 +31,19 @@ data class Optional<T : Any> constructor(private val value: T?) { | |
} | ||
} | ||
|
||
fun getOrElse(fn: () -> T): T { | ||
fun orElse(fn: () -> T): T { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not used at the moment) |
||
return value ?: fn() | ||
} | ||
|
||
fun hasValue(): Boolean { | ||
return value != null | ||
} | ||
fun hasValue(): Boolean = value != null | ||
|
||
companion object { | ||
fun <T : Any> from(value: T?): Optional<T> { | ||
return Optional(value) | ||
} | ||
fun <T : Any> from(value: T?): Optional<T> = Optional(value) | ||
|
||
fun <T : Any> empty(): Optional<T> { | ||
return Optional(null) | ||
} | ||
fun <T : Any> empty(): Optional<T> = Optional(null) | ||
} | ||
} | ||
|
||
fun <T : Any> T?.toOption() = Optional(this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (another new alias) |
||
|
||
fun <T : Any> T?.toOptional() = Optional(this) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import android.os.Build | |
import android.provider.MediaStore | ||
import androidx.annotation.WorkerThread | ||
import androidx.core.content.getSystemService | ||
import arrow.core.Try | ||
import okio.buffer | ||
import okio.sink | ||
import okio.source | ||
|
@@ -35,23 +34,21 @@ import java.io.File | |
* Save a string to a file with Okio. | ||
*/ | ||
@WorkerThread | ||
fun writeToFile(str: String, file: File): Try<Unit> { | ||
return Try<Unit> { | ||
file.sink().buffer().use { | ||
it.writeString(str, Charsets.UTF_8) | ||
} | ||
@Throws | ||
fun writeToFile(str: String, file: File) { | ||
file.sink().buffer().use { | ||
it.writeString(str, Charsets.UTF_8) | ||
} | ||
} | ||
|
||
/** | ||
* Save a byte array to a file with Okio. | ||
*/ | ||
@WorkerThread | ||
fun writeToFile(data: ByteArray, file: File): Try<Unit> { | ||
return Try<Unit> { | ||
file.sink().buffer().use { | ||
it.write(data) | ||
} | ||
@Throws | ||
fun writeToFile(data: ByteArray, file: File) { | ||
file.sink().buffer().use { | ||
it.write(data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those 2 fun are actually not used, but I do not want to delete this file. |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a new alias to avoid to many changes.