Skip to content

[WIP] issue-38 fix proposal #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package pl.msitko.xml.optics

import monocle.function.Index
import monocle.{Lens, Optional, Traversal}
import monocle.{Lens, Optional, Prism, Traversal}
import pl.msitko.xml.entities._
import pl.msitko.xml.matchers.NameMatcher

import scalaz.Applicative
import scalaz.std.list._
import scalaz.syntax.traverse._
Expand All @@ -23,6 +22,15 @@ trait ElementOptics {
def deeper(label: String): Traversal[Element, Element] =
deeper(NameMatcher.fromString(label))

def being(predicate: Element => Boolean): Prism[Element, Element] =
Prism[Element, Element]{ el =>
if (predicate(el)) {
Some(el)
} else {
None
}
}(identity)

val hasOneChild: Optional[Element, Node] = Optional[Element, Node]{ el =>
onlyChild(el)
}{ newNode => from =>
Expand Down