Continuation tasks in .NET TPL: a simple continuation example

Tasks in .NET TPL make it easy to assign tasks that should run upon the completion of another task.

We’ll need a basic object with a single property:

public class Series
{
	public int CurrentValue
	{
		get;
		set;
	}
}

Read more of this post

Introduction to CouchDB with .NET part 13: validation functions in design documents

Introduction

In the previous post we saw some additional examples of MapReduce functions in CouchDB view design documents. First we investigated the built-in _sum reducer which – as its name applies – can be used to sum up numerical values of the keys from the map phase. The reducer can sum up integers, arrays of integers and objects whose properties are integers. Then we looked at how grouping works and then continued with a brief discussion of custom reducers. We can write our own reducers in JavaScript but we need to make sure that we always return a single value. If we need multiple values from a reducer then can wrap them in a JSON object and return that. Also, the usage of the rereduce parameter is confusing at first and we might only need it in large data sets.

In this post we’ll take a look at another type of functions in design documents, namely validation functions.

Read more of this post

Lazy loaded sequences in F#

F# has a number of standard collection types that are available in other popular computing languages: lists, arrays, tuples. There’s, however, an odd one called a sequence. A sequence in F# is a normal collection for IEnumerable types but its members are lazily evaluated. This means that the sequence is not instantiated with all its elements included. Instead, its elements are evaluated when needed.

Here’s how we can declare a sequence:

Read more of this post

LINQ statements in F#

There’s very little difference between executing LINQ statements in C# and F#. Adding a reference to System.Linq in an F# file gives access to the same LINQ extension methods we’ve all come to love. There’s a choice between LINQ extension methods and LINQ queries with lambda statements. Any LINQ statement in C# can be directly ported to F# and will have the same result.

Note that many LINQ statements can be rewritten using built-in functions from the various collection types in F# such as List and Seq, e.g. List.average or Seq.map . In this short post we’ll just look at a couple of LINQ examples. There’s no point in regurgitating the various LINQ functions here. There’s a large collection on this blog available here if you are new to this topic.

Read more of this post

Introduction to CouchDB with .NET part 12: more MapReduce examples

Introduction

In the previous post we first saw how to insert and update design documents via the HTTP API. It is not very different from the equivalent operations on “normal” data documents. However, we need to consider the keywords in a design documents such as “views”, “map” and “reduce”. We also saw how to select compound keys and values in the map function of the view index. Compound keys are very helpful when executing more complex queries such as “select all users above the age 20 and an address in Washington”. We went through a number of examples about limiting the range of the result set using the startkey and endkey query parameters.

In this post we’ll continue where we left off previously and go through more MapReduce examples.

Read more of this post

Parallel LINQ in .NET C#: a basic example

Parallel LINQ – PLINQ – can be applied to LINQ to Objects. This type of LINQ which works with the IEnumerable and IEnumerable of T data types. There are extension methods in the PLINQ library that make parallel processing of the result from queries available. The result is that multiple data items are processed concurrently.

In fact it is not difficult to transform a “normal” LINQ statement to PLINQ.

Set up the data source:

Read more of this post

Introduction to CouchDB with .NET part 11: various MapReduce examples

Introduction

In the previous post we continued exploring view design documents in CouchDB. We first saw how to filter the documents that will be considered in the map phase. We then examined various simple operations on the key returned by the mapping. Our first reducer example included the usage of the built-in _count function for a simple count aggregation. Lastly we mentioned the usage of the stale query parameter to tell CouchDB how to handle the updating of the view indexes.

In this post we’ll continue looking at querying through views and MapReduce functions in CouchDB.

Read more of this post

Creating a detached child Task in .NET C#

A child Task, a.k.a a nested Task, is a Task that’s started within the body of another Task. The containing Task is called the parent.

A detached child Task is one which doesn’t have any relationship with the parent. The detached child Task will be scheduled normally and will have no effect on the parent.

There’s nothing special about creating a detached child Task:

Read more of this post

Introduction to CouchDB with .NET part 10: view design documents cont’d

Introduction

In theprevious post we started looking into a large and relatively complex topic within CouchDB namely design documents. Design documents are JSON documents like the data documents we’ve looked at so far but they have a special purpose. They use JavaScript for their logic. The JS functions are embedded in the JSON document which has sections for each type of role a design document can play: view, update, show/list, validation. We started discussing the view design documents that play an important role in querying a CouchDB database. We also introduced the idea of MapReduce that is heavily used in view-based queries.

In this post we’ll continue where we left off in the previous part and continue looking at how view design documents work. We’ll keep using the children database we created previously.

Read more of this post

Consuming C# functions with out parameters from F#

C# has a number of functions with “out” parameters such as the various “TryParse” functions like Int32.TryParse. Functions with out parameters typically have a primary return value, like TryParse returns a boolean. The out parameters are also populated within the body of the function. We can call them secondary return values. Here’s an example of using Int32.TryParse:

int res;
bool parseSuccess = Int32.TryParse("123", out res);

TryParse returns true if the string input was successfully parsed into an integer and “res” will be assigned that value. F# has no out values so how can we consume our functions from an F# program?

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

ARCHIVED: Bite-size insight on Cyber Security for the not too technical.