Skip to content

Instantly share code, notes, and snippets.

@ClaireNeveu
Last active April 11, 2017 01:22
Show Gist options
  • Save ClaireNeveu/4e3b642684ff40c6418083b4c05aad5f to your computer and use it in GitHub Desktop.
Save ClaireNeveu/4e3b642684ff40c6418083b4c05aad5f to your computer and use it in GitHub Desktop.
NonEmptyString
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