Skip to content

How to get field names from a record Schema? #30

Answered by SystemFw
caenrique asked this question in Q&A
Discussion options

You must be logged in to vote

@caenrique This is the start of a solution. It's in Scala 3 but written compatibly, in Scala 2 the only difference is how to install kind-projector:

//> using lib "org.typelevel::toolkit::0.1.10"
//> using lib "org.systemfw::dynosaur-core::0.6.0"
//> using option -Ykind-projector

import dynosaur._
import cats._, data._, arrow._, free._, syntax.all._

import Schema.structure._

object Names {
  def attributeNames[A](schema: Schema[A]): List[String] = 
    schema match {
      case Record(record) =>
        type Target[A] = List[String]
        def extract[R](recordSchema: FreeApplicative[Field[R, *], R]): List[String] =
          recordSchema
            .analyze {
              new Funct…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@SystemFw
Comment options

Comment options

You must be logged in to vote
1 reply
@caenrique
Comment options

Answer selected by caenrique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants