-
Notifications
You must be signed in to change notification settings - Fork 15
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 a couple inferred methods and aliases to clump api #88
Conversation
Interesting point @stevenheidel. Do you think it could be easier to use clumpSourceThatReturnsList.get(id).orElse(Clump.value(Nil)) Or if you don't like wrapping up the clumpSourceThatReturnsList.getOrElse(id, Nil) |
/** | ||
* Alias for [[value]] | ||
*/ | ||
def apply[T](value: T): Clump[T] = this.value(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep a behavior similar to Future.apply
[0], this method should propagate exceptions inside a Clump instance. Suggestion:
def apply[T](value: => T): Clump[T] = this.future(Future(value))
Same observation for the next method.
[0] https://github.com/scala/scala/blob/2.11.x/src/library/scala/concurrent/Future.scala#L492
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
@williamboxhall - I like your suggestion for a .getOrElse though. |
This is what .getOrElse would look like on ClumpSource: def getOrElse(input: T, default: => U): Clump[U] =
get(input).orElse(Clump(default)) |
About val clump: Clump[Option[T]] = Clump.value(someValue).optional |
@williamboxhall I wouldn't like to pollute the |
@fwbrasil - thanks, renamed |
@stevenheidel Thanks, could you add tests for the new methods? |
cdd24b6
to
935346b
Compare
@fwbrasil - Added tests for fallback, fallbackTo, and orElse. How would you like me to test the methods that are just synonyms? I don't really want to just copy the tests from the other methods. |
@stevenheidel Please add tests for all methods, we aim to keep the 100% code coverage. |
@fwbrasil - For the tests that are just synonyms of other methods do you want me to just copy the tests? |
@stevenheidel The test needs to check that the synonyms are pointing to the correct methods and passing the correct params. It is ok to copy an existing test if it tests the synonym properly. |
Thanks @stevenheidel! 👍 cc/ @williamboxhall |
@@ -47,6 +67,11 @@ sealed trait Clump[+T] { | |||
def filter[B >: T](f: B => Boolean): Clump[B] = new ClumpFilter(this, f) | |||
|
|||
/** | |||
* If this clump does not return a value then use the default instead | |||
*/ | |||
def orElse[B >: T: ClassTag](default: => B): Clump[B] = new ClumpOrElse(this, Clump.value(default)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
👍 some nice additions |
Add a couple inferred methods and aliases to clump api
The most useful of these to me is
default
. I want to be able to go:instead of having to do this all the time: