Skip to content

Instantly share code, notes, and snippets.

@DamianReeves
Created July 31, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamianReeves/897ace5f8996f56740eebd3d8acd2fd6 to your computer and use it in GitHub Desktop.
Save DamianReeves/897ace5f8996f56740eebd3d8acd2fd6 to your computer and use it in GitHub Desktop.
Field Properties
package datadictionary
import datadictionary.Field.Modifier
type AnyField = Field[?, Nothing, Nothing]
type AnyFieldHavingKeyOf[K <: Field.FieldKey] = Field[K, Nothing, Nothing]
final case class Field[Key <: Field.FieldKey, +A, +Attribs](key: Key) extends Serializable:
def asConstant(using Attribs <:< Modifier.Assignable) = ???
override def toString: String = key
override def hashCode(): Int = key.hashCode()
object Field:
type FieldKey = String & Singleton
def constant[K <: FieldKey](key: K): ConstantPartiallyApplied[K] = ConstantPartiallyApplied(key)
def string[K <: FieldKey](key: K): Field[K, String, Modifier.Assignable] =
Field[K, String, Modifier.Assignable](key)
object Modifier:
type Assignable
type ReadOnly
type Constant <: ReadOnly
class ConstantPartiallyApplied[K <: FieldKey](key: K) extends AnyVal:
def apply[A]: Field[K, A, Modifier.Constant] = as[A]
def as[A]: Field[K, A, Modifier.Constant] = Field[K, A, Modifier.Constant](key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment