Created
January 12, 2018 10:18
-
-
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.
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
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