我有这段代码可以正常工作:
var discoverEvents = events.map { event in
userEvents.find { $0.eventID == event.eventID } ?? event
}
我想知道是否有任何方法可以在event
内以某种方式引用find
:
var discoverEvents = events.map { userEvents.find { $$0.eventID == $0.eventID } ?? $0 }
使其成为单行?
答案 0 :(得分:6)
不,这是不可能的。内部$0
遮蔽外部$0
,并且没有其他方式可以引用外部范围中的import org.apache.jmeter.services.FileServer;
if (ResponseCode != null && ResponseCode.equals("200") == false) {
Failure = true;
// displays in Results Tree
FailureMessage ="Creation of a new CAE record failed. Response code " + ResponseCode + "." ;
// Static elements
part1 = "Creation of a new record failed. Response code: ";
part2 = ". Sorry!";
// Open File(s)
FileOutputStream f = new FileOutputStream("d:\\error.csv", true);
PrintStream p = new PrintStream(f);
// Write data to file
p.println( part1 + ResponseCode + part2 );
// Close File(s)
p.close();
f.close();
}
。
正如@DavidBerry所提到的,该语法适用于简短匿名函数。否则事情会变得非常混乱。