Rx: Where are the WindowWithTime, WindowWithCount operators? - system.reactive

I see these mentioned all over the web; however, they don't seem to exist when I import the latest Rx via NuGet. Were these methods renamed?

They're all overloads of Window now:
var maxWindowCount = 5;
.Window(maxWindowCount)
.Window(TimeSpan.FromSeconds(5))
Lee Campbell has a good article on Window, GroupJoin and Buffer:
http://leecampbell.blogspot.com/2011/03/rx-part-9join-window-buffer-and-group.html

Related

Reactive extensions documentation

I encountered an RX method that I have not seen before and went to MSDN to take a look at any documentation that there may be.
The method was
public static IObservable<IList<TSource>> CombineLatest<TSource> (this IEnumerable<Iobservable<TSource>> sources)
I am familiar with a CombineLatest that takes an Observable as a parameter and a transform function and returns an Observable.
Unfortunately MSDN only has a page for "Observable.CombineLatest<TFirst, TSecond, TResult> Method".
Am I looking in the wrong place or am I missing a better place to see RX API documentation, other than MSDN?
The MDSN documentation is awful. The two best sites I have found are http://introtorx.com and http://reactivex.io. Neither site though has info on that overload. :)
Basically once each observable has emitted a value, then combine latest emits a new list every time one of the streams emits one. The list contents are a list of the latest values from each of the child streams. If a stream completes, that value is propagated forever. If a stream errors, the combined stream errors.
You can run the following in LinqPad to demonstrate what it does:
var letters = new Subject<string>();
var numbers = new Subject<string>();
var observables = new IObservable<string>[] { letters, numbers };
var combineLatest = observables.CombineLatest();
combineLatest.Dump("CombineLatest");
numbers.OnNext("0");
numbers.OnNext("1");
letters.OnNext("A");
letters.OnNext("B");
numbers.OnNext("2");
letters.OnNext("C");
letters.OnNext("D");
numbers.OnCompleted();
letters.OnNext("E");
letters.OnError(new Exception());
Marble diagram:
Letters: ------A--B-----C--D-----E--x
Numbers: 0--1--------2--------|
--------
Combine: ------A1-B1-B2-C2-D2----E2-x

Variable increment in for loop doesn't work

I have this Swift code:
for var a = 0; a < 10; a++{
println(a)
}
There is an compile error on
a++{
Can anyone explain why?
You just need to add a space between a++ and {:
for var a = 0; a < 10; a++ {
println(a)
}
If you want to use the "{" against your variable you need to use the variable name between the "+" and the "{" as per the swift documentation
for var a = 0; a < 10; ++a{
println(a)
}
Another option as suggest ABakerSmith is to space the operators "+" and "{"
I particularly prefer the first option as it keeps my code consistent as I never use space before my "{" and also it is how is used through all apple documentation
#vacawama and ABakerSmith already told you how to fix it. The reason is that Swift uses whitespace to figure out the difference between multi-character expressions and separate expressions. It requires whitespace between symbols where languages like C don't. It still trips me up sometimes.
Also, for future reference, Swift code allows for two different For loop syntaxes.
for <initialization>; <condition>; <increment> { <statements> }
or when in an array or a collection
for <identifier> in <collection> { <statements> }
But both of them require the attention to detail on where your spaces are in the code, so be careful.
Also, since it seems like you may be rather new at Swift, I recommend checking out these awesome resources that make the journey of learning Swift a lot easier.
Apple's free 500 page Swift Code Reference Guide
Thinkster.io has a great guide for everything swift, even quick little cheat sheets to keep handy for any questions you might have in the future. When I learned swift I used this site a lot!
If you want to build a cool little game using swift start here!
Hope that helped! Swift is a great programming language that has a lot to offer, and I hope you have fun learning it!

How do I plot a data series in F#?

Over on FSHUB, LethalLavaLand said,
Let me plot my values!
So the question is, how can I plot a data series in F# using built-in .NET 4.0 controls?
Since I've been working with the built-in Microsoft Charting Controls in .NET 4.0 lately (and loving every minute of it!), I thought I'd take a crack at answering my own question...
#r "System.Windows.Forms.DataVisualization"
open System.Windows.Forms
open System.Windows.Forms.DataVisualization.Charting
type LineChartForm( title, xs : float seq ) =
inherit Form( Text=title )
let chart = new Chart(Dock=DockStyle.Fill)
let area = new ChartArea(Name="Area1")
let series = new Series()
do series.ChartType <- SeriesChartType.Line
do xs |> Seq.iter (series.Points.Add >> ignore)
do series.ChartArea <- "Area1"
do chart.Series.Add( series )
do chart.ChartAreas.Add(area)
do base.Controls.Add( chart )
let main() =
let data = seq { for i in 1..1000 do yield sin(float i / 100.0) }
let f = new LineChartForm( "Sine", data )
f.Show()
main()
Don't forget, you don't have to do everything in F#.
You can roll up all your F# calculations into a library or class, and then use that in whatever "Front End" language you want:
E.g you could easily marry F# back end
with WPF or Silverlight or C#
WinForms.
You may appreciate my parametric plot in F# that visualizes predator-prey dynamics using the new charting functionality in .NET 4. The original 5-line Mathematica solution becomes 19 lines of F# code. Not bad for a general-purpose language!
However, this is a one-shot solution and, consequently, is not very useful in F# interactive. To reuse the same functionality interactively you need to handle threading issues (marshalling data to and from a UI thread that handles a persistent GUI) as our F# for Visualization product does. The technique is also described in my Visual F# 2010 for Technical Computing book.

Does Scala have introspection capable of something similar to Python's dir()?

Yes, I know it's considered lazy by the non-Pythonistas. The reason I ask is that documentation is still woefully lacking in many Scala libraries (e.g. Scala-dbc, but that's not all I'm looking at), and if I could see the attributes of an object/class at runtime, I could at least figure out what's available. Thanks.
Scala does not have a reflection API. The only way to access this information is to use the Java reflection API. This has the disadvantage that the structure may change as the way Scala is represented in Java classes and interfaces may change in the future.
scala> classOf[AnyRef].getMethods
res0: Array[java.lang.reflect.Method] = Array(public final void ...
Some specific type information that is present in the byte code can be accessed with the ScalaSigParser.
import tools.scalap.scalax.rules.scalasig._
import scala.runtime._
val scalaSig = ScalaSigParser.parse(classOf[RichDouble])
That's one of my main uses for REPL. Type the object's name, dot, and then TAB and it will show all available methods.
It isn't perfect. For one thing, it shows protected methods, which won't be available unless you are extending the class. For another thing, it doesn't show methods available through implicit conversion.
And, of course, the IDEs are all capable of doing that.
You might want something like the following which would give you what you need. In this case, it operates on a String, obviously.
val testStr = "Panda"
testStr.getClass.getMethods.foreach(println)
Does that work?
You may want to use this little helper to beef up the REPL

Defining operators in Boo

I'm looking to move some of my lighter weight metaprogramming from Nemerle to Boo and I'm trying to figure out how to define custom operators. For example, I can do the following in Nemerle:
macro #<-(func, v) {
<[ $func($v) ]>
}
Then these two are equivalent:
foo <- 5;
foo(5);
I can't find a way of doing this in Boo -- any ideas?
While Boo supports operator overloading by defining the appropriate static operator function (op_addition), and also supports syntactic macros, it does not support creating custom operators at this time.
I'm not sure if this is exactly what you need but you can create syntactic macros in Boo. There's some information on the CodeHaus site, http://boo.codehaus.org/Syntactic+Macros, but the syntax has changed in one of the recent releases. I don't know of any tutorials on the new syntax but the source release for Boo 0.8.2 has some examples (some of the language structures are implemented as macros). If you don't want to download the full source a view of the SVN repository is available, https://svn.codehaus.org/boo/boo/trunk/src/Boo.Lang.Extensions/Macros/. The assert macro would be a good place to start.
HTH
Stoo