Created
October 8, 2019 09:15
-
-
Save txusballesteros/73bbef497f49c765442bc2c22c34397d to your computer and use it in GitHub Desktop.
Higher Kinded Types with Arrow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.Kind | |
import arrow.core.ForEither | |
import arrow.core.Option | |
import com.txusballesteros.codelabs.billboard.api.movie.MovieApi | |
import com.txusballesteros.codelabs.billboard.core.domain.mapper.map | |
import com.txusballesteros.codelabs.billboard.core.domain.model.Movie | |
internal class MovieCloudDataSource<F>( | |
private val api: MovieApi | |
) : MovieDataSource { | |
override fun <F> getMovie(id: String): Kind<F, Movie> = | |
Option.fromNullable(api.getMovie(id)).fold( | |
ifEmpty = { raiseError(RuntimeException()) }, | |
ifSome = { just(it.map()) } | |
) | |
} | |
fun main() { | |
val api = MovieApiMock() | |
val dataSource: MovieDataSource = MovieCloudDataSource(api) | |
val perico = dataSource.getMovie<ForEither>(1).fix() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment