Skip to content

nativelibs4java/scalaxy-records

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scalaxy/Records Build Status

VERY EARLY STAGE, THIS IS A PROOF-OF-CONCEPT

This is an abstraction of how data records can be stored in arrays of columns rather than rows of objects.

import scalaxy.records._

trait User[C[_]] extends Record[User] {
  val name: C[String]
  val birthDate: C[Date]
  val kudosCount: C[Int]
}

// This is a `Int => Record[User]#Array`.
val userFactory: Record[User]#Factory = recordFactory[User]
/* Macro expands to: {
  (size: Int) =>
    new Record[User]#Array {
      val name = new Array[String](size)
      val birthDate = new Array[Date](size)
      val kudosCount = new Array[Int](size)
    }
*/

val userGetters: Record[User]#Getters = recordGetters[User]
/* Macro expands to: {
  new Record[User]#Getters {
    val name = reified {
      (record: Record[User]#Array, row: Int) => record.name(row)
    }
    val birthDate = reified {
      (record: Record[User]#Array, row: Int) => record.birthDate(row)
    }
    val kudosCount = reified {
      (record: Record[User]#Array, row: Int) => record.kudosCount(row)
    }
  }
*/

val n = 10
val users = userFactory(n)
println("name column: " + users.name.toSeq)
println("birthDate column: " + users.birthDate.toSeq)
println("kudosCount column: " + users.kudosCount.toSeq)
for (i <- 0 until n) {
   val name = userGetters.name(users, i)
   println(s"i = $i, name = $name")
}

About

Macro-powered record abstractions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages