2019-11-12 21:13:01 +01:00
package moe.kageru.kagebot.extensions
2019-11-13 22:06:30 +01:00
import arrow.Kind
2019-11-12 21:13:01 +01:00
import arrow.core.Either
2019-11-13 16:59:44 +01:00
import arrow.core.Tuple3
2019-11-12 22:10:26 +01:00
import arrow.core.getOrElse
2019-11-13 22:06:30 +01:00
import arrow.typeclasses.Functor
2019-11-12 21:13:01 +01:00
fun < L , R > Either < L , R > . on ( op : ( R ) -> Unit ) : Either < L , R > {
this . map { op ( it ) }
return this
}
2019-11-12 22:10:26 +01:00
fun < T > Either < * , T > . unwrap ( ) : T = getOrElse { error ( " Attempted to unwrap Either.left " ) }
2019-11-13 16:59:44 +01:00
2019-11-13 23:18:28 +01:00
inline fun < A , B , C , A2 , F > Tuple3 < A , B , C > . mapFirst ( AP : Functor < F > , op : ( A ) -> Kind < F , A2 > ) = let { ( a , b , c ) ->
2019-11-13 22:06:30 +01:00
AP . run { op ( a ) . map { Tuple3 ( it , b , c ) } }
2019-11-13 16:59:44 +01:00
}
2019-11-13 23:18:28 +01:00
inline fun < A , B , C , B2 , F > Tuple3 < A , B , C > . mapSecond ( AP : Functor < F > , op : ( B ) -> Kind < F , B2 > ) = let { ( a , b , c ) ->
2019-11-13 22:06:30 +01:00
AP . run { op ( b ) . map { Tuple3 ( a , it , c ) } }
2019-11-13 16:59:44 +01:00
}