Skip to content

Commit

Permalink
Refactor update CloudAlbumDataSource to new bind
Browse files Browse the repository at this point in the history
  • Loading branch information
pakoito authored and jrgonzalezg committed Mar 5, 2017
1 parent f5df46b commit 257f23e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

package com.antonioleiva.bandhookkotlin.data

import com.antonioleiva.bandhookkotlin.*
import com.antonioleiva.bandhookkotlin.data.lastfm.LastFmService
import com.antonioleiva.bandhookkotlin.data.mapper.AlbumMapper
import com.antonioleiva.bandhookkotlin.domain.entity.Album
import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound
import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound
import com.antonioleiva.bandhookkotlin.repository.datasource.AlbumDataSource
import com.finecinnamon.Result
import com.finecinnamon.bind
import com.finecinnamon.raiseError
import com.finecinnamon.result

class CloudAlbumDataSource(val lastFmService: LastFmService) : AlbumDataSource {

override fun get(id: String): Result<AlbumNotFound, Album> =
binding {
bind {
val response = it binds lastFmService.requestAlbum(id).asyncResult()
val album = AlbumMapper().transform(response.album)
val r = it binds album.fold({ AlbumNotFound(id).raiseError()},{ it.result() })
Expand Down
2 changes: 1 addition & 1 deletion tools/src/main/java/com/finecinnamon/predef.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,4 @@ class NonEmptyList<out A> private constructor(
inline fun <reified A> of(head: A, vararg t: A): NonEmptyList<A> = NonEmptyList(head, t.asList())
fun <A> unsafeFromList(l: List<A>): NonEmptyList<A> = NonEmptyList(l)
}
}
}

0 comments on commit 257f23e

Please sign in to comment.