Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active August 29, 2015 13:57
Show Gist options
  • Save puffnfresh/9649776 to your computer and use it in GitHub Desktop.
Save puffnfresh/9649776 to your computer and use it in GitHub Desktop.
import scalaz.{PLens, @?>}
// Ah, breaks the prism laws!
// > val two = within(_ == 2, PLens.plensId)
// > two.set(2, 3).flatMap(two.get)
// None
def within[A, B](f: A => Boolean, p: A @?> B): A @?> B = PLens.plens { (a: A) =>
if (f(a))
p(a)
else
None
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment