我打电话给这样的网络服务:
WS
.url(url)
.get
.map { response => // error occurs on this line
response.status match {
case 200 => Right(response.json)
case status => Left(s"Problem accessing api, status '$status'")
}
}
Run Code Online (Sandbox Code Playgroud)
完整的错误: Error: Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global
我有一个元组,想要添加一个元素而不会失去类型安全性.这就是我想要实现的目标:
val tuple = ("", 1, 1f) // (String, Int, Float)
val newTuple:(String, Int, Float, Double) = tuple :+ 1d
Run Code Online (Sandbox Code Playgroud) 这是我正在使用的代码:
(__ \ "fields").read(
(__ \ "key").readNullable[String] and
(__ \ "summary").readNullable[String] and
(__ \ "description").readNullable[String]
tupled
)
Run Code Online (Sandbox Code Playgroud)
这种情况下的完整错误是:
value and is not a member of play.api.libs.json.Reads[Option[String]]
Run Code Online (Sandbox Code Playgroud)
它也可能是错误中的其中一个
play.api.libs.json.OFormat
play.api.libs.json.OWrites
Run Code Online (Sandbox Code Playgroud) 在JavaScript中,经常使用观察者模式.它有一个棘手的问题,那就是主体对观察者的参考.他们需要清理.对于常规应用程序,我使用以下经验法则:
subject.on('event', ...)observer.listenTo(subject, 'event', ...)在第二种情况下,listenTo它意识到观察者的生命周期,并且当观察者死亡时它将自动移除听众.
在现代SPA(单页应用程序)样式中,只有部分应用程序在任何时候都处于活动状态,这一点变得非常重要.如果将它与Web套接字结合起来,这是一个完美的事件流候选者,并且很可能长寿,这就变得更加重要.
使用FRP,类似于表示随时间变化的值的事件流,我(不知道)创建了大量的监听器.每个filter,map并flatMap创建一个绑定(可能使用一个监听器)到前一个流的新流.
在我看来,确定如何以及何时需要删除这些侦听器似乎相当棘手.我无法想象我是第一个考虑这个问题的人,但我在互联网上找不到这个.
我看到其他语言中的一些框架使用弱引用.JavaScript没有弱引用的概念(WeakMap在这里不可用).即使它有,但它似乎是一个坏主意,因为它不清楚垃圾收集何时发生.
我正在使用一些类(由于某种原因)只能在一个VM中使用一次.如果我fork := true在我的sbt设置中单独运行它们(),我的测试用例会起作用.
如果我运行多个这些测试,它们会失败,并且异常必须与线程执行程序拒绝任务(它很可能已关闭).找出导致问题的原因是非常耗时的,即使我发现问题,我也可能无法解决它(我无法访问源代码).
我目前正在使用specs2测试框架,但任何使用的测试框架sbt都是可以接受的.
是否有任何测试框架sbt能够在jvmfork 中运行每个测试?
关于可能的其他解决方案的想法或想法当然受到欢迎.
我不知道如何描述这个问题,所以我只会显示类型签名.
我有以下实例:
val x:Future[F[Future[F[B]]]] = ???
Run Code Online (Sandbox Code Playgroud)
我想要一个例子:
val y:Future[F[B]] = ???
Run Code Online (Sandbox Code Playgroud)
F 是一个Monad,所以我有以下方法:
def pure[A](a:A):F[A] = ???
def flatMap[A, B](fa:F[A], f:A => F[B]):F[B] = ???
def map[A, B](fa:F[A], f:A => B):F[B] = flatMap(fa, (a:A) => pure(f(a)))
Run Code Online (Sandbox Code Playgroud)
我认为以下内容应该有效,但感觉不对:
x.flatMap { fWithFuture =>
val p = Promise[F[B]]
flatMap(fWithFuture, (futureF: Future[F[B]]) => {
p.completeWith(futureF)
pure(())
})
p.future
}
Run Code Online (Sandbox Code Playgroud)
我缺少一个概念吗?
一些背景信息.我试图定义这样的函数:
def flatMap[A, B](fa:Future[F[A]], f: A => Future[F[B]]):Future[F[B]] = ???
Run Code Online (Sandbox Code Playgroud)
也许这在概念上是一件奇怪的事情.有关有用抽象的任何提示都是受欢迎的.
我有一组返回不同类型的方法:
Either[ErrorResponse, X]
Future[Either[ErrorResponse, X]]
Option[ErrorResponse]
Run Code Online (Sandbox Code Playgroud)
这些方法需要先前方法的结果来执行它们的计算.方法:
type Parameters = Map[String, String]
// allows me to flatmap on an either
implicit def toRightProjection[Failure, Success](e: Either[Failure, Success]) =
e.right
// converts anything to a future
implicit def toFuture[T](t: T) =
Future.successful(t)
// retrieves the request paramters from the given request
def requestParameters(request: RequestHeader): Either[ErrorResponse, Parameters] = ???
// retrieves the response type from the given parameters
def responseType(p: Parameters): Either[ErrorResponse, String] = ???
// retrieves the client id from the given …Run Code Online (Sandbox Code Playgroud) 我正在尝试为Play 2控制器创建一个函数测试,它将多部分表单数据作为输入.FakeRequest目前没有方法支持多部分表单POST.还有哪些方法可以测试这个控制器?
Map<String, Object> map = new HashMap<String, Object>();
map.put("param1", "test-1");
map.put("param2", "test-2");
map.put("file", file)
Result result = routeAndCall(fakeRequest(POST, "/register").withFormUrlEncodedBody(map));// NO SUCH METHOD
Run Code Online (Sandbox Code Playgroud)
编辑:这是我测试多部分的解决方法.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:3333/blobupload");
FileBody imageFile = new FileBody(new File("test/resources/test-1.jpg"));
StringBody guid1 = null;
StringBody guid2 = null;
try {
guid1 = new StringBody("GUID-1");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("key1", imageFile);
reqEntity.addPart("key2", guid1);
httppost.setEntity(reqEntity);
HttpResponse response;
try {
response = httpclient.execute(httppost);
HttpEntity resEntity …Run Code Online (Sandbox Code Playgroud) 我有一组我想调试的测试用例(一步一步,读取值等).如何设置我的sbt构建,以便我可以连接eclipse调试器?
在我的本地机器上,我有一个常春藤缓存,已经通过处理多个项目来填充.
在项目中X使用解析程序加载库.在项目中使用了相同的库,解决此库没有问题,因为它在我的本地缓存中.YAXB
当我的一个同事加载项目时,B他得到了X无法解析库的错误.问题:解析器Y丢失了.
如何在不删除常春藤缓存的情况下测试我的sbt项目是否有一套完整的解析器来解析所有依赖项?