Skip to content

Instantly share code, notes, and snippets.

@YA2O
Created January 12, 2018 10:18
Show Gist options
  • Save YA2O/6eca4c353c5754dcb41c6a7c51787500 to your computer and use it in GitHub Desktop.
Save YA2O/6eca4c353c5754dcb41c6a7c51787500 to your computer and use it in GitHub Desktop.
Container for non empty values. Uses Equal and Monoid type classes from Scalaz.
import scalaz.{Equal, Monoid}
import scalaz.Scalaz._
final case class NonEmpty[A] private[NonEmpty](value: A)
object NonEmpty {
def wrap[A: Monoid: Equal](value: A): Option[NonEmpty[A]] =
if (implicitly[Monoid[A]].zero === value)
None
else
Some(new NonEmpty(value))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment