Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何优雅地检测部分匹配?_Scala_Pattern Matching - Fatal编程技术网

Scala 如何优雅地检测部分匹配?

Scala 如何优雅地检测部分匹配?,scala,pattern-matching,Scala,Pattern Matching,我正在编写一个简单的HTTP服务器,我有这样的代码来解析请求字符串 val method :: url :: version :: rest = tokenize(requestString) if (rest != Nil) throw new IncorrectRequestException("Extra data after HTTP version") 函数的作用是:返回与变量列表匹配的字符串列表。那很好用 但是,我想添加漂亮的错误报告。例如,如果缺少HTTP版本,我想抛出In

我正在编写一个简单的HTTP服务器,我有这样的代码来解析请求字符串

val method :: url :: version :: rest = tokenize(requestString)
if (rest != Nil) 
  throw new IncorrectRequestException("Extra data after HTTP version")
函数的作用是:返回与变量列表匹配的字符串列表。那很好用

但是,我想添加漂亮的错误报告。例如,如果缺少HTTP版本,我想抛出IncorrectRequestException(“缺少HTTP版本”),而不是简单的MatchError异常


除了检查tokenize()调用结果的长度之外,还有什么好方法可以实现这一点吗?

组合分析器可能是您可以在这里介绍的最强大的技术。您还可以尝试从列表中获取一个
迭代器
,并连续调用
next
来检索值