ccadllc/cedi-config

Add support for NonEmptyList and NonEmptyVector

jrudnick opened this issue · 1 comments

Enhance API be adding support for NonEmptyList and NonEmptyVector:

An example of code would be:

def nonEmptyList[A](key: String)(cpl: String => ConfigParser[List[A]]): ConfigParser[NonEmptyList[A]] = cpl(key) bind { case head :: tail => ConfigParser.pure(NonEmptyList(head, tail)) case Nil => ConfigParser(s"non-empty-list failure for $key") { _ => Left(ConfigErrors.of(ConfigError.WrongType(ConfigKey.Relative(key), "expected non-empty list", None))) } }

and

def nonEmptyVector[A](key: String)(cpv: String => ConfigParser[Vector[A]]): ConfigParser[NonEmptyVector[A]] = cpv(key) bind { case Vector() => ConfigParser(s"non-empty-vector failure for $key") { _ => Left(ConfigErrors.of(ConfigError.WrongType(ConfigKey.Relative(key), "expected non-empty vector", None))) } case v => ConfigParser.pure(NonEmptyVector(v.head, v.tail)) }

This issue implies adding a dependency to cats.