8000 Add Var type. Closes #279. by cranst0n · Pull Request #511 · monix/monix · GitHub
[go: up one dir, main page]

Skip to content

Add Var type. Closes #279. - #511

Merged
alexandru merged 4 commits into
monix:masterfrom
cranst0n:iss-279-var
Jan 11, 2018
Merged

alexandru merged 4 commits into
monix:masterfrom
cranst0n:iss-279-var

Conversation

@cranst0n
Copy link
Copy Markdown
Contributor

No description provided.

@cranst0n
Copy link
Copy Markdown
Contributor Author

@alexandru First cut. Please advise if you want me to go more in depth with test/docs.

@codecov
codecov Bot commented Jan 10, 2018 •
Copy link
Copy Markdown

Codecov Report

Merging #511 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #511      +/-   ##
==========================================
- Coverage   90.11%   90.09%   -0.03%     
==========================================
  Files         359      360       +1     
  Lines        9380     9387       +7     
  Branches     1810     1810              
==========================================
+ Hits         8453     8457       +4     
- Misses        927      930       +3

@alexandru alexandru left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @cranst0n, some small changes needed — sorry about the formatting comments, it is now my intention to setup automatic code formatting, to avoid dragging PRs based on that (#513).

* or the `initialValue` (as the seed) in case no value has yet been emitted, then continuing
* to emit events subsequent to the time of invocation via an underlying [[ConcurrentSubject]].
*
* @see [[ConcurrentSubject]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I want a more detailed ScalaDoc with a sample preferably.

I'm thinking the sample should be like:

val a = Var(0)
val b = Var(0)

// Sum that gets re-calculated "reactively"
val sum = Observable.combineLatest(a, b)(_ + _)

// Subscribes for updates
sum.foreach(println)

a := 4
// => 4
b := 5
// => 9
a := 10
// => 15

And it should include a mention that this is equivalent with a ConcurrentSubject.behavior(Unbounded) that caches the current value for immediate usage.

value = update
underlying.onNext(update)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Get rid of blank line.

*/
final class Var[A] private (
initialValue: A
)(implicit scheduler: Scheduler)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

scheduler is too long, the type is more important here, just use s. And now definition fits on one line.

/** Builder for [[Var]] */
def apply[A](
initialValue: A
)(implicit scheduler: Scheduler): Var[A] = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly rename scheduler. Also initialValue => initial, since it's obvious it's a "value".

Sorry, personal pet peeve about redundant words in var names 😀

}

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Get rid of unneeded blank lines.

@alexandru
alexandru merged commit 7a3d8d0 into monix:master Jan 11, 2018
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.

2 participants

0