Skip to content

Commit

Permalink
fixup! fixup! fixup! Redesign context implementation
Browse files Browse the repository at this point in the history
VaultContext is no longer a case class
  • Loading branch information
NthPortal committed Aug 21, 2023
1 parent 69f48ee commit c58c71e
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import cats.syntax.functor._
import org.typelevel.vault.{Key => VaultKey}
import org.typelevel.vault.Vault

final case class VaultContext(vault: Vault) {
final class VaultContext(vault: Vault) {
def get[A](key: VaultContext.Key[A]): Option[A] =
vault.lookup(key.underlying)
def getOrElse[A](key: VaultContext.Key[A], default: => A): A =
get(key).getOrElse(default)
def updated[A](key: VaultContext.Key[A], value: A): VaultContext =
VaultContext(vault.insert(key.underlying, value))
new VaultContext(vault.insert(key.underlying, value))
}

object VaultContext extends (Vault => VaultContext) {
object VaultContext {
final class Key[A] private (
val name: String,
private[VaultContext] val underlying: VaultKey[A]
Expand All @@ -48,7 +48,7 @@ object VaultContext extends (Vault => VaultContext) {
}
}

val root: VaultContext = apply(Vault.empty)
val root: VaultContext = new VaultContext(Vault.empty)

implicit object Ctx extends Context[VaultContext] {
type Key[A] = VaultContext.Key[A]
Expand Down

0 comments on commit c58c71e

Please sign in to comment.