[英]Use Either with Future
我想使用dartz
功能樣式並執行以下操作:
Either<Failure, Response> result = await remoteDataSource.request() // Future<Response> request();
.then((response) => Right(response))
.catchError((failure) => Left(failure));
但似乎我不能這樣做:
錯誤:“Right<動態,響應>”類型的值不能分配給“Either<失敗,響應>”類型的變量。
那么,我怎樣才能以這種方式使用Either
with Future
呢?
這都是關於<generics>
。
.then((response) => Right(response)) // this is of type Right<dynamic,User>
你必須給編譯器所有正確的信息:
.then((response) => Right<Failure, Response>(response))
// or
.then((response) => right(response)) // a helper function which returns an Either
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.