-
-
Save davidandrzej/a89b14f5483045ac8ee2bddf6f463f9b to your computer and use it in GitHub Desktop.
Implicit scoping implementation of privacy layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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