aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/softwaremill/sttp/testing/streaming/ConvertToFuture.scala
blob: 943889079be1951bed065b6d6dd65273cbded0ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.softwaremill.sttp.testing.streaming

import com.softwaremill.sttp.Id
import scala.concurrent.Future
import scala.language.higherKinds
import scala.util.Try

trait ConvertToFuture[R[_]] {
  def toFuture[T](value: R[T]): Future[T]
}

object ConvertToFuture {

  val id: ConvertToFuture[Id] = new ConvertToFuture[Id] {
    override def toFuture[T](value: Id[T]): Future[T] =
      Future.successful(value)
  }

  val future: ConvertToFuture[Future] = new ConvertToFuture[Future] {
    override def toFuture[T](value: Future[T]): Future[T] = value
  }

  val scalaTry: ConvertToFuture[Try] = new ConvertToFuture[Try] {
    override def toFuture[T](value: Try[T]): Future[T] = Future.fromTry(value)
  }
}