Spotlight Topics

Most of the content on this page is related to one of the topics that I was recently interested in, so here you can find a page for every topic with some my articles, comments and other useful links:

Some Interests

Academic Stuff

As already mentioned, I'm a student of computer science at Faculty of Mathematics and Physics [^] of Charles University.

The topcis that I'm interested in are still changing :-), but you can find some up-to-date information on my academic page. My Bachelor thesis (it is available there) was about type-safe "AJAX" web development in F# with modality tracked in a type system using computation expressions (aka "monads"), so you can expect topics related to programming languages and tools...

Photography

I like taking photos, but updating the online gallery frequently was always a bit problem :-). That's why this page has a calendar, which shows a new picture every month (and also forces me to find and upload a new picture regularly).


Calendar - February 2010

More About Me

I'm student and Microsoft C# MVP from Prague, Czech Republic. I'm studying computer science at Charles University of Prague and I finished Bachelor studies in 2007.

Recently, I spent 3 months in Microsoft Research as an intern (with the F# team) and started wokring on the F# WebTools [^] project which allows developing "AJAX" applications purely in F# and this was also a topic of my thesis. I believe that F# and functional programming has a very promissing future.

The second topic that I'm involved in is maintaining of a project called Phalanger [^], which is a PHP language compiler started by my fellow students.

Latest Articles by Tomáš Petříček

Using custom grouping operators in LINQ

You can use LINQ to write queries that perform grouping of data using group by or ordering of data using orderby clause. LINQ provides the default (and the most common) implementation of both of the operations, but sometimes you may need a slightly different behavior when grouping or ordering data (this article is motivated by a question on StackOverflow which needs to do exactly that for grouping).

Let's look at a simple example, which shows when we may need a different behavior when grouping data. For example, we may have the following list of stock trades containing a name of a stock and the price of the trade (stored for example as a list of TradeInfo classes with properties Name and Price):

{ { Name = "MSFT", Price = 80.00 },
  { Name = "MSFT", Price = 70.00 },
  { Name = "GOOG", Price = 100.00 },
  { Name = "GOOG", Price = 200.00 },
  { Name = "GOOG", Price = 300.00 },
  { Name = "MSFT", Price = 30.00 },
  { Name = "MSFT", Price = 20.00 } }

Now, we may want to group adjacent trades into a single summary record which will contain the name of the stock (which is same for all trades in each group), the number of trades in the group and an average price in the group. The desired results are:

{ { Name = "MSFT", Count = 2, AvgPrice = 75.00 },
  { Name = "GOOG", Count = 3, AvgPrice = 200.00 },
  { Name = "MSFT", Count = 2, AvgPrice = 25.00 } }

The operation that we want to do is very similar to group by in LINQ, but it doesn't do quite the same thing! If we used group by, we would get only two groups as the result. However, as I wrote earlier, we want to group only adjacent trades. You could write your own extension method to do this, but then you need to leave the elegant LINQ query syntax. In this article, I'll show you how to get the desired results using a simple LINQ query with a group by clause...

Read the complete article
Sunday, February 07, 2010

More Recent Articles

Other Links

My Projects

  • F# Web Tools - Using the F# Web Tools you can author homogeneous client/server/database web applications in one type-checked project in F#. The distinction whether a code runs on the client (as JavaScript) or natively on the server is modeled using F# computation expressions.

  • Phalanger - PHP Language Compiler with several language extensions to allow smooth interoperability between PHP and other .NET (for example C#) code. Phalanger is complete enough to run applications like WordPress or MediaWiki.

  • LINQ Extensions - The project implements several useful extensions for the LINQ project. These extensions incude LINQ support for the C++/CLI language and simplified syntax or writing common types of database queries.

  • Other Projects Archive - Contains links to several older or partially completed projects that are no longer in active development, but may still be fun or even useful.