Learning F# : AboutTheStockExample koan

In the last couple of months, our Nashville .NET user group (@nashdotnet) has been working hard on learning F#. By the way, if you live in Nashville and are interested in Functional Programming, you can also join Nashville Functional Programmers or NashFP (@nashfp).

In the first week, we have walked through tutorials in try F# while the second week, we have played with F# Koans. The try F# tutorials have detailed explanation and code, and it will take you some time to finish it. F# Koans, by the way, is letting you learn F# by making the unit test (e.g., koan) pass. You can go through it pretty quickly, but you might not understand what’s going on much.

For the F# Koans, the last koan that I have done is AboutTheStockExample which is pretty challenging for F# newbie like me. Coming from C#, I have to resist thinking about applying loops or mutable variables. Anyway, after 15~ minutes of trial-and-error using F# interactive tool that comes with Visual Studio, I came up with the solution:

However, the solution looks just like someone is converting C# LINQ to F# Winking smile

If you want to find better solutions, a Leeds Sharp member has blogged about solving this koan while the best solution is shown in try F# site.

So far Learning F# is pretty fun and addicted journey although I haven’t spent time with it much yet (haven’t finished either try F# or Koans). Hopefully, I will get better with F# and start “Thinking functionally” soon.


How to detect when a user completes changing WinRT XAML Slider value?

Someone has asked me why we couldn’t detect when a user completes changing slider value (via dragging the slider thumb, clicking the slider, up/down keyboard and so on). At first, I was kind of surprise to learn that there is no such thing as a completed slider event.

However, if you think about it, how do you know when the value change event is over? You can’t really know unless you set a specific duration that you will be certain that a user is done with the slider.

So I think the best way to do it is to set up a timer to detect when our user stops interacting with the slider.

Let’s see the code:

Hope this helps!