Created
March 3, 2021 16:56
-
-
Save darkfrog26/d10f33ea1edf73460524c5f72b2051f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline def fromMapElems[A <: Product, T <: Tuple, L <: Tuple](map: Map[String, Value], index: Int, arr: Array[Any]): Unit = { | |
inline erasedValue[T] match | |
case _: (hd *: tl) => | |
inline erasedValue[L] match | |
case _: (hdLabel *: tlLabels) => | |
import fabric.rw.given | |
val hdLabelValue = constValue[hdLabel].asInstanceOf[String] | |
val hdValueOption = map.get(hdLabelValue) | |
val hdWritable = summonInline[Writer[hd]] | |
val valueOption = hdWritable.map(_.write(hdValue)) | |
def default = { | |
val defaultOption = ??? | |
defaultOption.getOrElse(throw new RuntimeException(s"Unable to find field $hd.${hdLabelValue} (and no defaults set) in ${Obj(map)}")) | |
} | |
val value = valueOption.getOrElse(default) | |
arr(index) = value | |
fromMapElems[A, tl, tlLabels](map, index + 1, arr) | |
case EmptyTuple => sys.error("Not possible") | |
case EmptyTuple => // Finished | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment