무료 모나드를 사용하는 ETL 프로세스에 간단한 언어를 구현했습니다. 데이터 가져 오기 및 저장 모두에 대해 입력 및 출력으로 List
을 사용하면 모든 것이 잘 동작합니다. 그러나 예상대로 나는 Future[List]
무료 모나드 사용 방법 [M [_]]
case class Fetch(offset: Int, amount: Int) extends Ops[Future[List[Record]]]
case class Store(recs: List[Record]) extends Ops[Future[List[Response]]]
def fetch(offset: Int, amount: Int): OpsF[Future[List[Record]]] =
liftF[Ops, Future[List[Record]]](Fetch(offset, amount))
def store(recs: List[Record]): OpsF[Future[List[Response]]] =
liftF[Ops, Future[List[Response]]](Store(recs))
// explicit types in case I am misunderstanding more than I think
def simpleEtl(offset: Int, amount: Int): Free[Ops, Future[List[Response]]] =
fetch(offset, amount).flatMap { rf: Future[List[Record]] =>
val getResponses: OpsF[Future[List[Response]]] = rf map { r: List[Record] =>
store(r)
}
getResponses
}
작동하지 List
case class Fetch(offset: Int, amount: Int) extends Ops[List[Record]]
case class Store(recs: List[Record]) extends Ops[List[Response]]
def fetch(offset: Int, amount: Int): OpsF[List[Record]] =
liftF[Ops, List[Record]](Fetch(offset, amount))
def store(recs: List[Record]): OpsF[List[Response]] =
liftF[Ops, List[Response]](Store(recs))
def simpleEtl(offset: Int, amount: Int): Free[Ops, List[Response]] =
fetch(offset, amount).flatMap(r => store(r))
작업을 비동기 라이브러리와 Future[List]
일반적인 수입과 작업과 정의
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import cats.free.Free
import cats.free.Free._
sealed trait Ops[A]
type OpsF[A] = Free[Ops, A]
를 사용하고는 에서 반환 된 유형 flatMap
/map
잘못이다 - 나는 OpsF[Future]
을 받고 있지 않다 그러나 Future[OpsF]
Error:(34, 60) type mismatch;
found : scala.concurrent.Future[OpsF[scala.concurrent.Future[List[Response]]]]
(which expands to) scala.concurrent.Future[cats.free.Free[Ops,scala.concurrent.Future[List[String]]]]
required: OpsF[scala.concurrent.Future[List[Response]]]
(which expands to) cats.free.Free[Ops,scala.concurrent.Future[List[String]]]
val getResponses: OpsF[Future[List[Response]]] = rf map { r: List[Record] =>
내 현재 해결 방법은 store
가 Future[List[Record]]
을 적용하고 Future
를 통해 통역지도를시키는 것입니다,하지만 어색한 느낌.
문제는 List
과 관련이 없습니다. 예 : Option
도 유용합니다.
내가 잘못 했습니까? 거기에 일종의 모나드 변압기가 있나요?
첫 번째 모습처럼 보인다에서이, 모나드 변압기의 일반적인 패턴처럼 보인다 하스켈은 어떻게 든'FreeT'를 가지고 있지만 스칼라즈 나 고양이에서는 찾을 수 없습니다. –
scalaz는 [7.2.0]부터'FreeT'를 가지고 있습니다 (https://oss.sonatype.org/service/local/repositories/releases/archive/org/scalaz/scalaz_2.11/7.2.0/scalaz_2.11-7.2). .0-javadoc.jar /!/index.html # scalaz.FreeT). –
곧 47 레벨의 도서관을 http://47deg.github.io/fetch/로 명명 할 수 있습니까? 곧 typelevel 인큐베이터가 될 것입니까? 47 도의 운동을하지는 않지만, 이미하고 싶은 일에 대한 해결책이 이미있는 것처럼 보입니다. – wheaties