Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NonEmptyList and NonEmptyVector #8

Open
jrudnick opened this issue Oct 2, 2017 · 1 comment
Open

Add support for NonEmptyList and NonEmptyVector #8

jrudnick opened this issue Oct 2, 2017 · 1 comment
Assignees

Comments

@jrudnick
Copy link

jrudnick commented Oct 2, 2017

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)) }

@jrudnick
Copy link
Author

jrudnick commented Oct 2, 2017

This issue implies adding a dependency to cats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant