widen
Given B is a sub type of C, re-type this value from Either to Either
import arrow.core.*
fun main(args: Array<String>) {
//sampleStart
val string: Either<Int, String> = "Hello".right()
val chars: Either<Int, CharSequence> =
string.widen<Int, CharSequence, String>()
//sampleEnd
println(chars)
}
Content copied to clipboard
Given B is a sub type of C, re-type this value from Ior to Ior
import arrow.core.*
fun main(args: Array<String>) {
//sampleStart
val string: Ior<Int, String> = Ior.Right("Hello")
val chars: Ior<Int, CharSequence> =
string.widen<Int, CharSequence, String>()
//sampleEnd
println(chars)
}
Content copied to clipboard
Given A is a sub type of B, re-type this value from Iterable to Iterable
import arrow.core.*
fun main(args: Array<String>) {
//sampleStart
val result: Iterable<CharSequence> =
listOf("Hello World").widen()
//sampleEnd
println(result)
}
Content copied to clipboard
Given A is a sub type of B, re-type this value from Option to Option
import arrow.core.Option
import arrow.core.some
import arrow.core.widen
fun main(args: Array<String>) {
val result: Option<CharSequence> =
//sampleStart
"Hello".some().map({ "$it World" }).widen()
//sampleEnd
println(result)
}
Content copied to clipboard
Given A is a sub type of B, re-type this value from Sequence to Sequence
import arrow.core.widen
fun main(args: Array<String>) {
//sampleStart
val result: Sequence<CharSequence> =
sequenceOf("Hello World").widen()
//sampleEnd
println(result)
}
Content copied to clipboard
Given A is a sub type of B, re-type this value from Validated to Validated
import arrow.core.*
fun main(args: Array<String>) {
//sampleStart
val string: Validated<Int, String> = "Hello".valid()
val chars: Validated<Int, CharSequence> =
string.widen<Int, CharSequence, String>()
//sampleEnd
println(chars)
}
Content copied to clipboard