Implicit scoping implementation of privacy layer
package com.sumologic.metplay | |
object ImplicitPrivacy { | |
sealed trait PrivacyLevel | |
case object High extends PrivacyLevel | |
case object Low extends PrivacyLevel | |
type High = High.type | |
type Low = Low.type | |
sealed trait HasLevel[L] | |
object Permissions { | |
implicit object HasLow extends HasLevel[Low] | |
implicit object HasHigh extends HasLevel[High] | |
} | |
def high[T](data: T): ImpSec[High, T] = new ImpSec(data) | |
def low[T](data: T): ImpSec[Low, T] = new ImpSec(data) | |
class ImpSec[PL <: PrivacyLevel, T](data: T) { | |
protected val _data = data | |
def fmap[S](f: T => S): ImpSec[PL, S] = new ImpSec(f(_data)) | |
def reveal(implicit has: HasLevel[PL]): T = _data | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment