/docs/40/40.md
http://github.com/osinka/subset · Markdown · 43 lines · 30 code · 13 blank · 0 comment · 0 complexity · 8a5943b384e0f85faf210b36bb938ab3 MD5 · raw file
- # Tuples
- Sometimes you may want to serialize fields in batches, e.g. two or
- three at a time. __Subset__ has a mechanism for this, it is a `Tuple`
- serializer.
- Assuming there is a couple of fields defined
- ```scala
- val f = "f".fieldOf[Int]
- val g = "g".fieldOf[String]
- ```
- An expression `f ~ g` will create a serializer (and extractor as well)
- for `Tuple[Int,String]`. Thus:
- ```scala
- val Tfg = f ~ g
- val mutation = Tfg( 10 -> "str" )
- ```
- Here `mutation` will be equivalent to `f(10) ~ g("str")`.
- And the extractor will look like:
- ```scala
- dbo match {
- case Tfg(i, s) =>
- case smthElse =>
- }
- ```
- Tuples of higher arity are possible too:
- ```scala
- val T3 = Tfg ~ "b".fieldOf[Boolean]
- ```
- > Tuple serializers/deserializers depend on all of their types
- > `ValueWriter`s and `ValueReader`s respectively.
- * * *