/docs/40/40.md
Markdown | 43 lines | 30 code | 13 blank | 0 comment | 0 complexity | 8a5943b384e0f85faf210b36bb938ab3 MD5 | raw file
1# Tuples 2 3Sometimes you may want to serialize fields in batches, e.g. two or 4three at a time. __Subset__ has a mechanism for this, it is a `Tuple` 5serializer. 6 7Assuming there is a couple of fields defined 8 9```scala 10val f = "f".fieldOf[Int] 11val g = "g".fieldOf[String] 12``` 13 14An expression `f ~ g` will create a serializer (and extractor as well) 15for `Tuple[Int,String]`. Thus: 16 17```scala 18val Tfg = f ~ g 19 20val mutation = Tfg( 10 -> "str" ) 21``` 22 23Here `mutation` will be equivalent to `f(10) ~ g("str")`. 24 25And the extractor will look like: 26 27```scala 28dbo match { 29 case Tfg(i, s) => 30 case smthElse => 31} 32``` 33 34Tuples of higher arity are possible too: 35 36```scala 37val T3 = Tfg ~ "b".fieldOf[Boolean] 38``` 39 40> Tuple serializers/deserializers depend on all of their types 41> `ValueWriter`s and `ValueReader`s respectively. 42 43* * *