Skip to content

Commit

Permalink
Remove KeyedIndexedList.unsafeMapValues in favor of a safe one.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddburnside committed Oct 28, 2024
1 parent a2654d6 commit 2f5468b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object ObservationValidationsTableBody {
"Request Approval",
onClick = props.observations.mod(
// this also gets rid of any buttons on "affected" observations
_.unsafeMapValues(_.updateToPendingIfConfigurationApplies(config))
_.mapValues(Observation.id)(_.updateToPendingIfConfigurationApplies(config))
) >>
ObsQueries.createConfigurationRequest[IO](row.id).void.runAsync
).tiny.compact.some
Expand Down
12 changes: 9 additions & 3 deletions model/shared/src/main/scala/explore/data/KeyedIndexedList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ case class KeyedIndexedList[K, A] private (private val list: TreeSeqMap[K, (A, N
def updatedValueWith(key: K, f: A => A): KeyedIndexedList[K, A] =
updatedWith(key, (v, i) => (f(v), i))

// WARNING - Do not use to update the part of the value used as a key
def unsafeMapValues(f: A => A): KeyedIndexedList[K, A] =
KeyedIndexedList(TreeSeqMap.from(list.map { case (k, (a, idx)) => (k, (f(a), idx)) }))
def mapValues(keyLens: Lens[A, K])(f: A => A): KeyedIndexedList[K, A] =
KeyedIndexedList(
TreeSeqMap.from(
list.map { case (_, (a, idx)) =>
val newA = f(a)
(keyLens.get(newA), (newA, idx))
}
)
)

object KeyedIndexedList:
def empty[K, A]: KeyedIndexedList[K, A] = KeyedIndexedList[K, A](TreeSeqMap.empty)
Expand Down

0 comments on commit 2f5468b

Please sign in to comment.