Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created December 4, 2018 17:44
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 davidandrzej/a89b14f5483045ac8ee2bddf6f463f9b to your computer and use it in GitHub Desktop.
Save davidandrzej/a89b14f5483045ac8ee2bddf6f463f9b to your computer and use it in GitHub Desktop.
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