Come sarebbe questo codice sguardo alla Scala di idiomatica C #?
-
30-09-2019 - |
Domanda
mi sono imbattuto in questo veramente bello codice Scala guardando mentre la ricerca di XMPP per un progetto Net a cui stiamo lavorando:
object Main {
/**
* @param args the command line arguments
*/
def main(args: Array[String]) :Unit = {
new XMPPComponent(
new ComponentConfig() {
def secret() : String = { "secret.goes.here" }
def server() : String = { "communitivity.com" }
def subdomain() : String = { "weather" }
def name() : String = { "US Weather" }
def description() : String = { "Weather component that also supported SPARQL/XMPP" }
},
actor {
loop {
react {
case (pkt:Packet, out : Actor) =>
Console.println("Received packet...\n"+pkt.toXML)
pkt match {
case message:Message =>
val reply = new Message()
reply.setTo(message.getFrom())
reply.setFrom(message.getTo())
reply.setType(message.getType())
reply.setThread(message.getThread())
reply.setBody("Received '"+message.getBody()+"', tyvm")
out ! reply
case _ =>
Console.println("Received something other than Message")
}
case _ =>
Console.println("Received something other than (Packet, actor)")
}
}
}
).start
}
}
(Questo è stato preso da http: / /github.com/Communitivity/MinimalScalaXMPPComponent/blob/master/src/org/communitivity/echoxmpp/Main.scala )
L'attore e il pattern matching aspetto cose come davvero un bel modo di componenti di scrittura in modo scalabile. Non sono stato in grado di trovare qualsiasi C # attori librerie che sembrano maturare e imparare Axum sembra eccessivo.
Quale sarebbe il modo giusto per attaccare questo in C #? (Ignorando il codice specifico XMPP, ovviamente - Sono più interessato a ciò che la versione C # di attori e pattern matching sarà simile).
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow