Last active
April 11, 2017 01:22
-
-
Save ClaireNeveu/4e3b642684ff40c6418083b4c05aad5f to your computer and use it in GitHub Desktop.
NonEmptyString
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
package nonemptystring | |
import macrame.delegate | |
import scala.collection.immutable.StringOps | |
final case class NonEmptyString(val head : Char, val tail : String) { | |
@delegate | |
override def toString : String = head + tail | |
} | |
object NonEmptyString { | |
def fromString(s : String) : NonEmptyString = | |
if (s.isEmpty) | |
Some(NonEmptyString(s.charAt(0), s.substring(1))) | |
else | |
None | |
implicit def toStringOps(nes : NonEmptyString) : StringOps = new StringOps(nes.toString) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment