common fun <A, C, B : C> Either<A, B>.widen(): Either<A, C>
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)
}
common fun <A, C, B : C> Ior<A, B>.widen(): Ior<A, C>
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)
}
common fun <B, A : B> Iterable<A>.widen(): Iterable<B>
Given A is a sub type of B, re-type this value from Iterable to Iterable
Kind -> Kind
import arrow.core.*
fun main(args: Array<String>) {
//sampleStart
val result: Iterable<CharSequence> =
listOf("Hello World").widen()
//sampleEnd
println(result)
}
common fun <B, A : B> List<A>.widen(): List<B>
fun <K, B, A : B> Map<K, A>.widen(): Map<K, B>
common fun <B, A : B> Option<A>.widen(): Option<B>
Given A is a sub type of B, re-type this value from Option to Option
Option -> 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)
}
common fun <B, A : B> Sequence<A>.widen(): Sequence<B>
Given A is a sub type of B, re-type this value from Sequence to Sequence
Kind -> Kind
import arrow.core.widen
fun main(args: Array<String>) {
//sampleStart
val result: Sequence<CharSequence> =
sequenceOf("Hello World").widen()
//sampleEnd
println(result)
}
common fun <E, B, A : B> Validated<E, A>.widen(): Validated<E, B>
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)
}
Do you like Arrow?
✖