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

paramsNonEmpty returns NonEmptyList[A] #582

Merged
merged 1 commit into from
Apr 5, 2016

Conversation

sergeykolbasov
Copy link
Collaborator

As it was discussed earlier: #577 (comment)

@sergeykolbasov sergeykolbasov force-pushed the params-non-empty branch 2 times, most recently from 7262942 to 7f0f5a0 Compare March 30, 2016 17:40
@codecov-io
Copy link

Current coverage is 74.08%

Merging #582 into master will decrease coverage by -1.23% as of 0ddd693

Powered by Codecov. Updated on successful CI builds.

@@ -337,11 +338,13 @@ trait Endpoints {
* at least one element) multi-value query-string param `name` from the request into a `Seq` or
* raises a [[Error.NotPresent]] exception when the params are missing or empty.
*/
def paramsNonEmpty(name: String): Endpoint[Seq[String]] =
def paramsNonEmpty(name: String): Endpoint[NonEmptyList[String]] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about introducing a new function paramsNel and keeping the old one (behind deprecation)? I want to keep the API unchanged and I think paramsNel sounds like a reasonable name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's introduce new method

@sergeykolbasov sergeykolbasov force-pushed the params-non-empty branch 4 times, most recently from 54e4b6f to b28454b Compare April 4, 2016 21:43
*/
def paramsNel(name: String): Endpoint[NonEmptyList[String]] =
option(items.ParamItem(name))(requestParams(name)).mapAsync({
case values if values.exists(_.nonEmpty) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify that and perform just a single traversal? Something like:

.mapAsync { values => values.filter(_.nonEmpty) match {
  case hd :: tl => Future.value(NonEmptyList(hd, tl))
  case _ => Future.exception(Error.NotPresent(items.ParamItem(name)))
}}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emh, but in that case it could contain empty parameters

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see.

@@ -24,6 +23,10 @@ import shapeless._
*/
object Main extends App {

(1,2,3) match {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unwanted changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should go sleep :(

@vkostyukov
Copy link
Collaborator

Thanks @imliar! Merging this!

@vkostyukov vkostyukov merged commit 836566a into finagle:master Apr 5, 2016
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

Successfully merging this pull request may close these issues.

3 participants