我目前正在实现一个库来序列化和反序列化XML-RPC消息.它几乎已经完成,但现在我正在尝试使用Shapeless删除当前asProduct方法的样板.我目前的代码:
trait Serializer[T] {
def serialize(value: T): NodeSeq
}
trait Deserializer[T] {
type Deserialized[T] = Validation[AnyErrors, T]
type AnyErrors = NonEmptyList[AnyError]
def deserialize(from: NodeSeq): Deserialized[T]
}
trait Datatype[T] extends Serializer[T] with Deserializer[T]
// Example of asProduct, there are 20 more methods like this, from arity 1 to 22
def asProduct2[S, T1: Datatype, T2: Datatype](apply: (T1, T2) => S)(unapply: S => Product2[T1, T2]) = new Datatype[S] {
override def serialize(value: S): NodeSeq = {
val params = …Run Code Online (Sandbox Code Playgroud) 假设我有一个代表一组几个有效状态的特征。将对象存储在数据库中是一种好习惯吗?使用隐式函数MappedColumnType.base [Int,DoorState]存储Ints并将其映射到DoorState会更好吗?
trait DoorState
case object Open extends DoorState
case object Closed extends DoorState
class Doors(tag: Tag) extends Table[Door](tag, "DOORS") {
...
def state = column[DoorState]("DOOR_STATE")
...
}
Run Code Online (Sandbox Code Playgroud) 我没有在Scalaz github repo中找到任何对xml模块的引用.在分支系列/ 7.1.x中,它不是最新的.此外,没有任何关于使用Scalaz进行xml处理的文档(这很奇怪).知道为什么吗?
据我所知,没有真正的替代大型XML处理.反xml被放弃了(虽然no.arktekk有更新版本),但scala-xml存在性能问题.
你推荐我任何值得一试的项目吗?我知道ScalesXml,但我不太了解它.
我正在使用Scala中的XML,解析在内存资源有限的系统中可以达到~20MB的文件.我必须读取整个文件,我必须从中提取所有数据.更具体的是,我必须读取的节点具有有限的属性和值.
我想知道在性能方面最好的方法是什么(或者两者都具有相同的性能).我问这个是因为我不知道Scala如何处理它的XML库,我可能会遗漏一些细节.
第一种方法
def firstApproach(root: Elem) =
for { n <- root \ "node" } yield handleNodeAttribute(n)
private def handleNodeAttribute(n: Node) = n match {
case node @ <node /> if (node \ "@attr").text == "type1" => // do something
// here other possible cases -> type2, type3
}
Run Code Online (Sandbox Code Playgroud)
第二种方法
def secondApproach(root: Elem) = {
val nodes = root \ "node"
val type1 = filterNodesByAttribute(nodes, "attr", "type1")
// and so on -> type2, type3 …Run Code Online (Sandbox Code Playgroud) 我正在使用Weechat.我知道Gitter有一个IRC,而Weechat我打算连接到它.Irssi有很多指南,而不是Weechat.但是,我试图使用类似的命令到Irssi,我收到错误.
我怎么能和Gitter一起使用Weechat?
有谁知道我们如何以自动方式从任何Seq转换为_*?每次我们有Seq时强制类型并且方法使用类型为vararg的参数非常麻烦.
def mean[T: Numeric](elems: T*): Double
...
elems = Seq(1.0, 2.0, 3.0)
mean(elems) // this doesn't compiles
mean(elems: _*) // this compiles but it is cumbersome
Run Code Online (Sandbox Code Playgroud)