Skip to content

Instantly share code, notes, and snippets.

@crakjie
Created March 19, 2015 18:18
Show Gist options
  • Save crakjie/96c70ce095cc153e478e to your computer and use it in GitHub Desktop.
Save crakjie/96c70ce095cc153e478e to your computer and use it in GitHub Desktop.
Hack seq to add scalaz disjonction as operator which make a left when the list is empty
import scalaz.{\/, \/- ,-\/}
implicit final class SeqOps[A](seq : Seq[A]) {
def \/>[T](t : T) : T \/ Seq[A] = if (seq.isEmpty) -\/(t) else \/-(seq)
}
//usage
val right = Seq(1,2) \/> "Oh a nel!"
val left = Nil \/> "!#& a Nil !!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment