-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
...la/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2Optics.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.knora.webapi.messages.v2.responder.resourcemessages | ||
|
||
import monocle.* | ||
import monocle.macros.* | ||
|
||
import org.knora.webapi.messages.SmartIri | ||
import org.knora.webapi.messages.v2.responder.valuemessages.ReadValueV2 | ||
|
||
object ResourceMessagesV2Optics { | ||
|
||
type ReadResourceV2Values = Map[SmartIri, Seq[ReadValueV2]] | ||
|
||
object ReadResourceV2Optics { | ||
|
||
val values: Lens[ReadResourceV2, ReadResourceV2Values] = GenLens[ReadResourceV2](_.values) | ||
|
||
private def inValues(predicate: Seq[ReadValueV2] => Boolean): Optional[ReadResourceV2Values, Seq[ReadValueV2]] = | ||
Optional[ReadResourceV2Values, Seq[ReadValueV2]](_.values.find(predicate))(newValue => | ||
values => | ||
values.map { | ||
case (k, v) if predicate(v) => (k, newValue) | ||
case other => other | ||
}, | ||
) | ||
|
||
def values(predicate: Seq[ReadValueV2] => Boolean): Optional[ReadResourceV2, Seq[ReadValueV2]] = | ||
values.andThen(inValues(predicate)) | ||
} | ||
} |
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