Feeding a function result into a pattern matching function in F#

Say we have an F# function that returns a tuple of two elements:

let isGreaterThan x y =     
    if x > y then (true, x - y)
    else (false, 0)

…, i.e. we return true and the difference between the two input integers if the first integer is greater. Otherwise we return a false and a 0. Here’s how we can consume this function:

Read more of this post

Introduction to CouchDB with .NET part 9: starting with view design documents

Introduction

In the previous post we looked at data replication in CouchDB. Data replication means that the documents of a source database are copied over to the target database. At the end of the replication process the source and target databases should have the exact same set of documents where even the revision IDs are the same. Data replication is a means of creating backups and archives. It is also great if we need to test a function on real-life production data. We can run the tests on the replicated data set as much as we want without any effect on the production system. Data replication can be a one-off event or a continuous flow of data synchronisation.

In this post we’ll start looking into a large topic within CouchDB, namely design documents.

Read more of this post

Examining a Type in .NET C#

You can get hold of Types in a variety of ways. You can extract the Types available in an Assembly as follows:

Assembly executingAssembly = Assembly.GetExecutingAssembly();
Type[] typesAttachedToAssembly = executingAssembly.GetTypes();

Console.WriteLine("Types attached to executing assembly: ");
foreach (Type type in typesAttachedToAssembly)
{
	Console.WriteLine(type.FullName);
}

Read more of this post

Introduction to CouchDB with .NET part 8: data replication

Introduction

In the previous post we saw how to view changes made to a database. The _changes API endpoint returns a JSON with the list of changes. There are various filter functions to view only certain document IDs or include the properties of the document in the response.

In this post we’ll take a look at data replication between two databases.

Read more of this post

Summary of thread-safe collections in .NET

The System.Collections.Concurrent namespace has 4 thread-safe collections that you can use in multi-threaded applications. The starting point is that you have a multi-threaded app where the same collection needs to be accessed by different threads. In that case the well-know collection types, like HashSet, List, Dictionary etc. simply won’t be enough.

If many different threads have access to the same resource then there’s no guarantee on the state of that resource in the moment a thread accesses it in some way: deletion, lookup, insertion or modification. Another thread may have accessed the same resource just milliseconds before that and the other thread will access the resource under the wrong assumptions. You’ll end up with buggy code with unpredictable results and ad-hoc fixes and patches that probably won’t solve the root of the problem.

Read more of this post

Introduction to CouchDB with .NET part 7: viewing changes made in the database

Introduction

In the previous post we looked at batch insertions and updates in CouchDB. Batch operations are very useful if we intend to insert or update multiple documents at once. We can mix insertions, updates and deletions in the same batch operation. The individual modifications in the batch are treated in isolation. This implies that if one modification fails then it won’t affect the others. In other words batch operations are non-atomic in CouchDB.

In this post we’ll look at a way to check what changes have been made to a CouchDB database.

Read more of this post

Feeding a function result into a pattern matching lambda expression in F#

Say we have an F# function that returns a tuple of two elements:

let isGreaterThan x y =     
    if x > y then (true, x - y)
    else (false, 0)

…, i.e. we return true and the difference between the two input integers if the first integer is greater. Otherwise we return a false and a 0. Here’s how we can consume this function:

Read more of this post

Lambda expressions in F#

Lambda expressions in F# are inline anonymous functions, i.e. functions without a name. They are typically short and concise functions that are not meant to be reused.

Here’s a normal F# function that adds three numbers:

let addThreeNumbers x y z = x + y + z

This is a conventional named function that can be invoked from other parts of the application. We can convert it to a lambda function using the “fun” keyword. However, it must be invoked in place.

Read more of this post

Introduction to CouchDB with .NET part 6: batch updates and insertions

Introduction

In the previous post we looked at the CouchDB concurrency implementation and the notion of eventual consistency. Concurrency in a database means that multiple threads might want to access and modify the same data record at the same time. CouchDB solves the concurrency problem by a mechanism called Multi-Version Concurrency Control MVCC. With MVCC CouchDB keeps the various revisions of the same document. If a thread wants to read the document while it is being updated then the reading thread will get the most recent complete copy of the document. The caller will in such a case get an outdated revision of the document. However, a subsequent request will then get the updated copy. This scenario is called eventual consistency. CouchDB reaches high availability due to the absence of data locks and sacrifices data consistency to some degree.

In this post we’ll look at batch updates and insertions.

Read more of this post

Cancel multiple Tasks at once in .NET C#

You cannot directly interrupt a Task in .NET while it’s running. You can do it indirectly through the CancellationTokenSource object. This object has a CancellationToken property which must be passed into the constructor of the Task:

CancellationTokenSource cancellationTokenSource	= new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;

You can re-use the same token in the constructor or several tasks:

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.