Skip to content

Commit

Permalink
Merge pull request #252 from gemini-hlsw/preserve-env
Browse files Browse the repository at this point in the history
add Cursor.envR
  • Loading branch information
milessabin authored Aug 15, 2022
2 parents f609672 + e4a55ef commit 4736cf5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/core/src/main/scala/cursor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ trait Cursor {
def tpe: Type = context.tpe

def withEnv(env: Env): Cursor
def env: Env

protected def env: Env

def env[T: ClassTag](nme: String): Option[T] = env.get(nme).orElse(parent.flatMap(_.env(nme)))

def envR[T: ClassTag: TypeName](nme: String): Result[T] =
env.getR(nme) match {
case err @ Ior.Left(_) => parent.fold[Result[T]](err)(_.envR(nme))
case ok => ok
}

def fullEnv: Env = parent.map(_.fullEnv).getOrElse(Env.empty).add(env)

/**
Expand Down

0 comments on commit 4736cf5

Please sign in to comment.