Two functions showing how to filter functional lists using the specified predicate. First version uses naive recursion and the second one is tail-recursive using the accumulator parameter.
76 people like thisPosted: 14 years ago by Tomas Petricek
Create sequence of floating point values generated by random walk process. Functional solution using sequence expressions and yield! construct in a tail-call position.
39 people like thisPosted: 14 years ago by Tomas Petricek
Classical "Hello world" example that prints a message to the console output. This version uses F# printfn function to do the printing.
185 people like thisPosted: 14 years ago by Tomas Petricek
Generates a friendly string describing a date relatively to the current date and time. The function returns strings like "2 secs ago", "yesterday" or "3 years ago".
42 people like thisPosted: 14 years ago by Tomas Petricek
The snippet shows how to support slicing in a type. Slicing allows you to get for example a 2D sub-matrix of a matrix and is implemented by adding GetSlice member.
49 people like thisPosted: 14 years ago by Tomas Petricek
This snippet shows how to create objects with events in F#. It shows both simple event (to be used from F#) and a .NET compatible event with specific delegate type.
84 people like thisPosted: 14 years ago by Tomas Petricek
Shows how to use the 'ExprShape' module to recursively traverse an entire quotation and how to write quotation transformations. As an example, the snippet replaces all numeric constants in the quotation and then runs the transformed code.
26 people like thisPosted: 14 years ago by Tomas Petricek
A function that takes every Nth element of a sequence where N is passed as an argument. The snippet shows a naive function and a function using IEnumerator directly to provide an efficient implementation.
36 people like thisPosted: 13 years ago by Tomas Petricek
Searches all (currently loaded) types using Reflection to find the types with longest and shortest names of members. Uses average length of all type member names as a metric.
13 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows a simple implementation of the dynamic operator (?) that uses Dynamic Language Runtime and the C# implementation of dynamic operations. The snippet shows how to invoke instance methods with single argument.
34 people like thisPosted: 13 years ago by Tomas Petricek
The snippet defines computation builder for working with IEnumerator. The bind operation (let!) reads next element from the enumerator, so the computation can be used for expressing things that cannot be written just using seq.
29 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a Line chart. The sample generates a 2D spline calculated using sin and cos functions.
11 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a BoxPlot diagram. In this sample, we provide six statistics (Maxmimum, Minimum, Upper quartile, Lower quartile, Average and Median) about observations explicitly.
23 people like thisPosted: 13 years ago by Tomas Petricek
Defines an F# computation builder for encoding imperative computations. The 'return' construct returns immediately and terminates the rest of the computation. It is also possible to return value from a 'for' or 'while' loop.
11 people like thisPosted: 13 years ago by Tomas Petricek
The snippet declares a helper for creating asynchronous controllers for ASP.NET MVC 3. It declares a new base class for asynchronous actions that exposes a computation builder for writing actions using F# asynchronous workflows.
8 people like thisPosted: 13 years ago by Tomas Petricek
This sample implements "Hello, world!" as a WebSharper application. It demonstrates how to compose HTML/XML using combinators, how to dynamically create a button with a handler and how to update an existing DOM element.
4 people like thisPosted: 13 years ago by Tomas Petricek
A function implemented using sequence expressions that returns all subsets of a specified set. The function is not optimized, but it is very easy to understand.
11 people like thisPosted: 13 years ago by Tomas Petricek
This snippet extends several types from the System.Net namespace. It provides an easy to use API for creating asynchronous (as well as synchronous) HTTP servers using F# asynchronous workflows.
4 people like thisPosted: 13 years ago by Tomas Petricek
This snippet shows two improvements to asynchronous HTTP proxy from: http://fssnip.net/6e. First extension is to process page in chunks (instead of downloading the entire content first). The second extension is to use simple agent-based in-memory cache for previously visited pages.
7 people like thisPosted: 13 years ago by Tomas Petricek
The function has the same type as Seq.reduce. Instead of reducing elements from the left to the right, it splits the input into two halves, reduces each half separately and then aggregates the results using the given function. This means that the values are aggregated into a ballanced tree, which can save stack space.
2 people like thisPosted: 13 years ago by Tomas Petricek
The snippet uses asynchronous sequences (from F# AsyncExtensions) to download historical stock data from Yahoo. Data is downloaded in a buffered way on demand (as needed) and returned line by line. The sample then prints OHLC values for first 30 items.
6 people like thisPosted: 13 years ago by Tomas Petricek
Implements the Observable.windowed function that creates an observable returning a sliding window. The function is an observable version of Seq.observable. The implementation uses a simple F# agent that keeps partial windows and sends them to an observer.
6 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows how to implement reusable memoization function and how to use it to implement efficient Fibonacci number generator using dynamic programming.
6 people like thisPosted: 13 years ago by Tomas Petricek
Computation builder for writing non-deterministic computations.
8 people like thisPosted: 13 years ago by Tomas Petricek
Simple domain-specific language (DSL) for describing financial contracts in F#. A contract is represented using a discriminated union. Evaluating a contract gives the orders that may happen at a given date.
8 people like thisPosted: 13 years ago by Tomas Petricek
A function that nests items of a sequence that do not match a specified predicate under the last item that matches the predicate. The input is a sequence of values and the result is a sequence of pairs where the second element is a list of nested items.
3 people like thisPosted: 12 years ago by Tomas Petricek
The snippet implements a function "expand" that takes a quotation and performs two operations. It replaces all calls to methods marked with ReflectedDefinition with the body of the method and it simplifies all expressions that can be reduced in call-by-name style (let binding & application of lambda).
7 people like thisPosted: 12 years ago by Tomas Petricek
The sample shows two different reprezentations of Tesco checkout. The first one stores scanned items - as a list of either purchase or cancel items - and the second stores final bill with product and total quantity. The snippet implements transformation that corresponds to finalizing the purchase.
3 people like thisPosted: 12 years ago by Tomas Petricek
Domain-specific language for detecting patterns in stock prices. Run using try F#.
5 people like thisPosted: 12 years ago by Tomas Petricek
A sample that translates simple F# quotations (method calls, property getters) to stnadard C# LINQ expression trees.
7 people like thisPosted: 12 years ago by Tomas Petricek
Implements simple library for downloading Yahoo stock prices and displaying charts in Try F#. This snippet loads another one with examples.
2 people like thisPosted: 12 years ago by Tomas Petricek
Yet another tutorial based on the DSL for modelling financial contracts. This part just loads library for downloading prices & loads another snippet. Designed to run in Try F#.
0 people like thisPosted: 12 years ago by Tomas Petricek
Simple walkthrough that demonstrates how to estimate the value of PI using Monte Carlo simulation. A few holes need to be filled in and then you can run & parallelize the sample!
4 people like thisPosted: 12 years ago by Tomas Petricek
This snippet shows different options for reporting events from an F# agent. The options include triggering the event directly, using a thread pool or using a specified synchronization context.
3 people like thisPosted: 12 years ago by Tomas Petricek
The snippet implements Async.StartCancellable method that can be used to start a given workflow and then cancel it. The cancellation of the workflow is done asynchronously, which means that the caller will wait until the workflow is actually cancelled.
6 people like thisPosted: 12 years ago by Tomas Petricek
The snippet implements 'List.partitionWhile' which behaves as a combination of 'Seq.takeWhile' and 'Seq.skipWhile': It splits the list into a part containing elements from the beginning of a list that match a given predicate and remaining elements.
7 people like thisPosted: 12 years ago by Tomas Petricek
This snippet adds the 'GetSlice' operation to Math.Net vector and matrix types. This makes it possible to get sub-vectors and sub-matrices using the convenient syntax (For vectors 'vect.[start .. end]` or 'vect.[start ..]' and for matrices 'mat.[r1 .. r2, c1 .. c2]' and similar).
9 people like thisPosted: 12 years ago by Tomas Petricek
An example that shows how we can represent unique names (using classes) and how to substitute names in any F# type type defined using records, discriminated unions and tuples.
0 people like thisPosted: 12 years ago by Tomas Petricek
Just another DSL for creating HTML in F#. This DSL attempts to have nice syntax using curly brackets (F# computation expression blocks) for nesting. It does not use other keywords like `yield` (to keep the syntax as non-intrusive as possible), but that means the implementation relies on mutation. I think there could be nicer implementation using automatic quoting in F# 3.0.
17 people like thisPosted: 11 years ago by Tomas Petricek
A simple asynchronous workflow that retries running a given async workflow (until "resultOk" function returns true or until a specified number of retries is performed). The function uses tail-recursion in async workflows.
24 people like thisPosted: 11 years ago by Tomas Petricek
The snippet shows how to create an F# function value that will call a custom finalizer function when garbage collected. This is done by creating a type that inherits from FSharpFunc.
8 people like thisPosted: 11 years ago by Tomas Petricek
F# introduction course - Exploring World Bank data in Try F#
0 people like thisPosted: 11 years ago by Tomas Petricek
F# introduction course - Getting data about Titanic passengers using CSV type provider and analyzing them using standard sequence-processing functions known from LINQ. To be used in Try F#.
1 people like thisPosted: 11 years ago by Tomas Petricek
A simple library that reads XML documents into user-defined F# types. The user defines a set of discriminated unions that model the elements of the file and a library automatically creates these types from a XML file.
10 people like thisPosted: 11 years ago by Tomas Petricek
A function to display digit from ML coding Dojo by Mathais
0 people like thisPosted: 11 years ago by Tomas Petricek
What feature would I like to see in F#? One thing is the ability to implement an interface in a class by delegating the implementation to an expression. This snippet demonstrates the idea using a simple example of vectors.
7 people like thisPosted: 11 years ago by Tomas Petricek
Another version of the xBahve quick start example, this time using custom F# computation builder to make the code nicer. We define a builder for step and custom functions for Given/And/When/Then.
3 people like thisPosted: 11 years ago by Tomas Petricek
A function to initialize 2D array that supports failures - if the initializer fails to produce value for any of the array locations, the construction is stopped and the function returns 'None'
3 people like thisPosted: 10 years ago by Tomas Petricek
A simple example that creates a frame from a list of dictionaries. Each dictionary is treated as a row that maps column keys to values. The trick is to use Deedle value expansion.
1 people like thisPosted: 10 years ago by Tomas Petricek
A simple script that checks whether 1.0 is really the identity element of multiplication for 32bit floating-point numbers.
0 people like thisPosted: 10 years ago by Tomas Petricek
Different ways of generating numerical ranges in F#. It turns out that the built-in syntax generates fairly slow code, so the snippet shows two alternative ways that are faster. Any compiler optimizations making the built-in one faster would be nice :-)
6 people like thisPosted: 10 years ago by Tomas Petricek
This sample uses the internals of the Freebase type provider to get the names of all the entities that Freebase knows about. The snippet returns the type names, so some of the type provider internals are exposed, but it still returns nice list of entities.
0 people like thisPosted: 10 years ago by Tomas Petricek
Agent demo
12 people like thisPosted: 10 years ago by Tomas Petricek
Implements a simple agent that lets you throttle the degree of parallelism by limiting the number of work items that are processed in parallel.
7 people like thisPosted: 10 years ago by Tomas Petricek
This is a "library" for validation that collects all validation errors (and does not use the heavy-weight machinery of monads). This is perhaps a simpler variant that could be used e.g. here: http://tinyurl.com/lv2nwkl
7 people like thisPosted: 9 years ago by Tomas Petricek
A very simple function to print hello world, which is completely useless. Just testin the F# Snippets API...
1 people like thisPosted: 9 years ago by Tomas Petricek
Simplistic helpers for formatting dates and strings in a web server (strip HTML tags when reading RSS feeds, nicely format dates etc.)
2 people like thisPosted: 9 years ago by Tomas Petricek
Example of integrating DotLiquid with a simple Suave server. The snippet automatically registers all public members of a record as members that can be accessed by DotLiquid templates.
5 people like thisPosted: 9 years ago by Tomas Petricek
Inspired by @theburningmonk, this snippet defines a couple of extensions and operators that can be used to make F# as short and as obscure as APL. Complete with a 19 character solution of the Euler problem #1!
7 people like thisPosted: 9 years ago by Tomas Petricek
Alternative solution to the problem in Scott Wlaschin's "Reinventing the Reader Monad" article (but without monads).
3 people like thisPosted: 9 years ago by Tomas Petricek
This is a somewhat sensible solution to the flappy bird dojo by Phil Trelford. It uses sequence expressions eliminate some mutation of the flappy bird. To play this sample on Windows simply copy the code from the raw view and execute in F# interactive, for cross platform implementations check out: http://trelford.com/prognet15.zip
6 people like thisPosted: 9 years ago by Tomas Petricek
im in ur forms, updating ur snippets!
0 people like thisPosted: 9 years ago by Tomas Petricek
Quick script using FsLab that visualizes the aggregate number of downloads of a NuGet package over time, using the HTML type provider to get the data from www.nuget.org.
2 people like thisPosted: 9 years ago by Tomas Petricek
A function that is like 'Seq.choose' but stops producing values as soon as the first 'None' value is produced.
3 people like thisPosted: 8 years ago by Tomas Petricek
Reading the F# snippets RSS feed using the F# Data XML type provider. Look, you now get tool tips for type providers too!
1 people like thisPosted: 8 years ago by Tomas Petricek
Solve the 8 queens problem in F#, keeping available positions on the board as a list of X,Y coordinates.
2 people like thisPosted: 8 years ago by Tomas Petricek
Analyze results of the fsharpWorks annual F# community survey to figure out what are the most popular F# tools and libraries. The snippet does some minimal data cleanup, but more work is needed to get precise results!
1 people like thisPosted: 8 years ago by Tomas Petricek
The snippet shows how to extract list of Olympic medalists from the Rio 2016 web site in a nice JSON format. It turns out you just need the right regular expression to extract the data from a script tag...
2 people like thisPosted: 8 years ago by Tomas Petricek
Do you want to format F# snippets, but cannot easily run the F# Formatting library as part of your documentation processing? We just added F# Formatting as a service (FAAS!) API to the F# Snippets. This code snippet shows how to call the service.
2 people like thisPosted: 8 years ago by Tomas Petricek
The snippet shows a minimal example of phantom types for type-safe way of tracking different types of IDs in a simple system.
7 people like thisPosted: 5 years ago by Tomas Petricek
Inspired by https://10print.org, this is a small incomplete BASIC interpreter that can generate a maze.
5 people like thisPosted: 4 years ago by Tomas Petricek
Every spot in the puzzle belongs to a (horizontal) row and a (vertical) column, as well as to one single 3x3 square (which we call "square" for short). At the beginning, some of the spots carry a single-digit number between 1 and 9. The problem is to fill the missing spots with digits in such a way that every number between 1 and 9 appears exactly once in each row, in each column, and in each square.
3 people like thisPosted: 3 years ago by Tomas Petricek
Computation expression that automatically captures the rest of the sequence that you are iterating over using a "for" loop so that the exception handler can do something clever with it.
0 people like thisPosted: 2 years ago by Tomas Petricek
The snippet extends a web crawler from snippet http://fssnip.net/3K. It synchronizes all printing using an additional agent (so printed text does not interleave) and the crawling function returns an asynchronous workflow that returns when crawling completes.
0 people like thisPosted: 1 year ago by Tomas Petricek
Interactive computation that asks the user questions
9 people like thisPosted: 6 months ago by Tomas Petricek
Three functions showing how to implement projection for functional lists. First version uses naive recursion and the second one is tail-recursive using the accumulator parameter. The third version extends this with continuation passing.
73 people like thisPosted: 14 years ago by Tomas Petricek
Windows Forms tutorial showing how to create form with button and how to register an event handler. When the button is clicked, the form changes its background color.
48 people like thisPosted: 14 years ago by Tomas Petricek
Classical "Hello world" example that prints a message to the console output. This version uses .NET Console.WriteLine method to do the printing.
31 people like thisPosted: 14 years ago by Tomas Petricek
Add extension to System.Type that returns the name of type including generic arguments in a nice readable format. It returns only short names of generic type and type arguments.
21 people like thisPosted: 14 years ago by Tomas Petricek
A domain specific language for creating layout using Windows Forms. The snippet implements combinators for creating controls and simple automatic arrangement of them.
43 people like thisPosted: 14 years ago by Tomas Petricek
Concatenating paths shouldn't be done just using string concatenation, because the directory separator may differ on various platforms. This snippet shows a simple custom operator for working with paths.
27 people like thisPosted: 14 years ago by Tomas Petricek
An asynchronous sequence is similar to the seq
Posted: 14 years ago by Tomas Petricek
The Let active pattern demonstrated by this snippet can be used to assign values to symbols in pattern matching. This is useful for writing complex pattern matching using match as we can handle multiple cases using a single clause.
64 people like thisPosted: 13 years ago by Tomas Petricek
Computation builder that provides easy way of constructing IDisposable objects. It supports elegant composition of disposable objects using 'do!' which can be used for example when working with 'IObservable' type.
42 people like thisPosted: 13 years ago by Tomas Petricek
Demonstrates how to implement the dynamic operator (?) using .NET Reflection. The implementation supports calling constructors, propreties and methods using simple overload resolution (based on parameter count). It handles instance as well as static members.
71 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a Bar chart. The sample shows population sizes in different continents.
23 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a Candlestick chart visualizing stock prices. The sample uses price of MSFT stocks over 20 days.
17 people like thisPosted: 13 years ago by Tomas Petricek
The snippet demonstrates how to compose simple asynchronous functions and how to use try .. with to handle exceptions in asynchronous workflows.
35 people like thisPosted: 13 years ago by Tomas Petricek
Declares an event combinator 'Event.using' that automatically releases resources allocated by a previous event occurence. Each event occurence creates a value using a function specified by the user and automatically calls 'Dispose' when generating a new value.
2 people like thisPosted: 13 years ago by Tomas Petricek
The snippet demonstrates how to write a general power function that has correct type involving units-of-measure. The function uses numbers represented using types. The snippet is mainly an example of what can be done (not recommended for the real world).
5 people like thisPosted: 13 years ago by Tomas Petricek
Agent that can be used for controlling the number of concurrently executing asynchronous workflows. The agent runs a specified number of operations concurrently and queues remaining pending requests. The queued work items are started as soon as one of the previous items completes.
21 people like thisPosted: 13 years ago by Tomas Petricek
The snippet implements a wrapper for standard F# agent that can be cancelled using the IDisposable interface. This makes it possible to use the agent locally (e.g. inside asynchronous workflow). When it is no longer needed, the agent's body is cancelled.
11 people like thisPosted: 13 years ago by Tomas Petricek
This snippet shows the implementation of three HTTP proxy servers in F#. The first is written using simple synchronous style (that isn't scalable). The second version uses event-based approach in the Node.js style, but is difficult to write. The third version uses F# async workflows and is both scalable and easy to write.
7 people like thisPosted: 13 years ago by Tomas Petricek
The snippet implements Async.Choice method that takes several workflows and creates a workflow, which returns the first result that was computed. After a workflow completes, remaining workflows are cancelled using the F# async cancellation mechanism. (The method doesn't handle exceptions.)
7 people like thisPosted: 13 years ago by Tomas Petricek
This snippet demonstrates programming using asynchronous sequences. It contains (hidden) implementation of AsyncSeq type and combinators for working with it. More importantly, it demonstrates how to use asynchronous sequences to implement a simple sequential on-demand crawler.
11 people like thisPosted: 13 years ago by Tomas Petricek
Implements a simple Async.StartDisposable extension that can be used to easily create IObservable values from F# asynchronous workflows. The method starts an asynchronous workflow and returns IDisposable that cancels the workflow when disposed.
4 people like thisPosted: 13 years ago by Tomas Petricek
Non-deterministic choice operation for F# asynchronous workflows - creates a workflow that returns the result of one of two asynchronous workflows, depending on which completes first. (The other workflow is not cancelled.)
4 people like thisPosted: 13 years ago by Tomas Petricek
Agent that keeps a cache of web pages that were downloaded previously. The agent handles messages to add and get data as well as message to clear the cache.
7 people like thisPosted: 13 years ago by Tomas Petricek
Using World Bank type provider and FSharpChart to show average university enrollment in Czech Republic, European Union and OECD members.
6 people like thisPosted: 13 years ago by Tomas Petricek
The snippet shows a simple F# agent that calculates average from the received values. It supports one message for adding numbers to the statistics and one for resetting the state. Moreover, the agent limits the processing rate to 1 message per second.
6 people like thisPosted: 12 years ago by Tomas Petricek
The snippet shows how to send HTTP POST request to a web page and download the generated HTML result. The POST data is encoded as a byte array and written to the request stream of HttpWebRequest.
10 people like thisPosted: 12 years ago by Tomas Petricek
Domain model for the Tesco checkout implemented in F# using discriminated unions (in 20 lines of code) and console-based user interface for scanning products and calculating the total price.
5 people like thisPosted: 12 years ago by Tomas Petricek
Simple domain-specific language for modeling of financial contracts.
8 people like thisPosted: 12 years ago by Tomas Petricek
Examples that use domain-specific langauge for detecting price patterns. To run the sample, load the previous snippet in TryF#. It opens the sample automatically.
2 people like thisPosted: 12 years ago by Tomas Petricek
An extension of MailboxProcessor that catches all unhandled exceptions (in the body of the mailbox processor) and reports them using an event. Otherwise, the public interface is the same as for MailboxProcessor.
5 people like thisPosted: 12 years ago by Tomas Petricek
Sample code using a simple library for downloading Yahoo stock prices. The demo shows how to process sequences and so on (to run this, load & run previous snippet).
1 people like thisPosted: 12 years ago by Tomas Petricek
Yet another tutorial based on the DSL for modelling financial contracts. This is a walkthrough with examples and tasks that is loaded by the previous 'Setup' snippet. Designed to run in Try F#.
0 people like thisPosted: 12 years ago by Tomas Petricek
This snippet generates a punched card image from a text. It punches holes in the places where a letter would be written and you can use it to generate jokes such as this one: http://bit.ly/M2oqOw
7 people like thisPosted: 12 years ago by Tomas Petricek
Simple implementation of Conway's Game of Life for the TryF# web site.
0 people like thisPosted: 12 years ago by Tomas Petricek
The snippet implements 'map' and 'init' functions for the 'ObservableCollection' type. These are similar to well-known functions for sequences, but 'map' works in an incremental fashion. When the source collection changes, the resulting collection is updated.
3 people like thisPosted: 12 years ago by Tomas Petricek
A simple domain specific langauge (DSL) that can be used to specify and recognize patterrns in 2D arrays. A pattern is defined by composing primitive checks, rotating and translating patterns. See also: http://t.co/6Poty4FL
3 people like thisPosted: 12 years ago by Tomas Petricek
Sample for Coding Kata
3 people like thisPosted: 12 years ago by Tomas Petricek
The example shows how to extend F# 3.0 'query' builder with a new custom operation that will work with standard lists, but also with queries that are translated using LINQ expressiont trees (such as databases).
12 people like thisPosted: 11 years ago by Tomas Petricek
An implementation of the ? operator that handles null
3 people like thisPosted: 11 years ago by Tomas Petricek
The snippet shows how to extend the built-in F# async computation builder with the ability to await standard .NET tasks using the let! keyword.
18 people like thisPosted: 11 years ago by Tomas Petricek
Parsing simple formulas using active patterns
2 people like thisPosted: 11 years ago by Tomas Petricek
F# introduction course - Getting data about cyclones from Freebase and plotting the dependency of damages in USD on the wind speed (with linear regression). To be used in Try F#.
3 people like thisPosted: 11 years ago by Tomas Petricek
F# introduction course - Get and read the Titanic data set using CSV type provider, define the type of "feature" and use it to classify the data and then implement a simple decision tree that can be used for writing more complex classifiers. To be used in Try F#.
7 people like thisPosted: 11 years ago by Tomas Petricek
The snippet defines a combinator 'tailrec' that can be used to express tail-recursive functions. If you use 'tailrec' and do not mark your function as recursive, then the function will be a tail-recursive one.
1 people like thisPosted: 11 years ago by Tomas Petricek
A simple example that shows how to refactor discriminated unions to extract common members
3 people like thisPosted: 11 years ago by Tomas Petricek
The snippet shows how to define the "=>" operator in F# so that it can be used for creating named parameters for dynamic API.
7 people like thisPosted: 11 years ago by Tomas Petricek
F# version of the code samples from an article "Fun with infinite sums" by Phil Haack. Using infinite sequences to separate the concerns and F# charting for simpler visualization.
5 people like thisPosted: 10 years ago by Tomas Petricek
A simple function that creates a counter function (with localized mutable state).
2 people like thisPosted: 10 years ago by Tomas Petricek
Different ways to write lazy values - using the lazy keyword or the Lazy.Create function. Pick the one you like the most!
2 people like thisPosted: 10 years ago by Tomas Petricek
Forgotten file for F# Works |> Paris!!!
4 people like thisPosted: 10 years ago by Tomas Petricek
Split a list into chunks using the specified separator. This takes a list and returns a list of lists (chunks) that represent individual groups, separated by the given separator 'v'
1 people like thisPosted: 10 years ago by Tomas Petricek
Async demo...
3 people like thisPosted: 10 years ago by Tomas Petricek
The snippet implements a simple agent that limits the number of parallelism. When created, the agent takes the maximum number of tasks it can run in parallel. When it receives a "Start" message, it will then either run the task, or store it in a queue until earlier task ha completed.
12 people like thisPosted: 10 years ago by Tomas Petricek
A more idiomatic definition of a Rational type with custom operators.
1 people like thisPosted: 10 years ago by Tomas Petricek
When you get an exception from the F# Compiler Service, it usually does not print any useful information. But you can look at the private fields of the exception and get some more useful things out of it...
0 people like thisPosted: 9 years ago by Tomas Petricek
3D castle sample from the Fun3D project, now written using WebGL and running in a web browser...
2 people like thisPosted: 9 years ago by Tomas Petricek
Parses UNIX time stamp into DateTime (as returned for example by the OpenWeatherMap API)
5 people like thisPosted: 9 years ago by Tomas Petricek
The .. operator that is used to generate ranges in F# core is quite slow. This snippet shows an alternative implementation that is about 5 times faster.
5 people like thisPosted: 9 years ago by Tomas Petricek
A snippet demonstrating the F# feature request to relax some of the indentation rules.
2 people like thisPosted: 9 years ago by Tomas Petricek
This is a crazy solution to the flappy bird dojo by Phil Trelford. It defines a custom computation builder to eliminate all mutation of the flappy bird. The script uses WPF and is playable on Windows in F# interactive, just copy the raw version, and for cross-platform implementations download: http://trelford.com/prognet15.zip
3 people like thisPosted: 9 years ago by Tomas Petricek
Based on the article "We’re now averaging more than one mass shooting per day in 2015", this calculates when is the best time to go to US to avoid being shot.
3 people like thisPosted: 9 years ago by Tomas Petricek
Minimal coding kata setup that I use in my trainings - the aim is to use as simple F# syntax as possible and to have a nice way for specifying placeholders that attendees are required to fill.
2 people like thisPosted: 9 years ago by Tomas Petricek
This is a reader monad, whit the difference that multiple reads access different parts of the state. This is done by building up a tuple (in the bind operator) that represents different parts of the state that can be accessed by different parts of the computation.
5 people like thisPosted: 9 years ago by Tomas Petricek
This looks for the first available port and starts a Suave server on the port. The function is asynchronous and returns the port once the server is started.
5 people like thisPosted: 8 years ago by Tomas Petricek
The snippet declares a function that groups adjacent elements of a sequence. A new group is started when the specified predicate holds about an element. Groups are constructed eagerly (using lists).
2 people like thisPosted: 8 years ago by Tomas Petricek
Creates an observable that returns windows of size 'n' (or smaller at the start) containing 'n' past values produced by observable 'source'. The order of items in the returned buffers is not guaranteed (it's a circular buffer).
3 people like thisPosted: 8 years ago by Tomas Petricek
The snippet looks at the number of signatures for the petition to do a second Brexit referendum. It uses JSON type provider to parse the data from the web site & Google charts to visualize the results.
0 people like thisPosted: 8 years ago by Tomas Petricek
This handy snippet calculates how much memory your Slack client uses. Use at your own risk. Mental safety cannot be guaranteed.
3 people like thisPosted: 8 years ago by Tomas Petricek
Dependency injection using the cutting edge programming language research, also known as global mutable variable. Is this a serious snippet or not? No category theory and mocking frameworks are required, so probably not.
5 people like thisPosted: 6 years ago by Tomas Petricek
A simple script that automatically recompiles LaTeX documents when they are saved. Works nicely when editing papers in Atom and using SumatraPDF for preview (Sumatra automatically reloads PDF documents). Does not report errors or anything clever (!)
1 people like thisPosted: 5 years ago by Tomas Petricek
A simple example of how to define a custom type that enforces extra business rules by using a single-case discriminated union with a private constructor
7 people like thisPosted: 4 years ago by Tomas Petricek
A version of AsyncSeq.groupBy where the user can synchronously request all groups, but also all elements in each group during iteration and the operation does not deadlock.
0 people like thisPosted: 2 years ago by Tomas Petricek
The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a Doughnut chart. The sample shows proportion of seats taken by parties in UK elections.
6 people like thisPosted: 2 years ago by Tomas Petricek
An example showing how to process list in a pipeline. We first use List.filter to return only even numbers and then use List.map to format them as strings.
4 people like thisPosted: 7 months ago by Tomas Petricek
Higher-order functions for working with nested lists that reimplement various useful List module functions, but work on nested lists, preserving the original nesting strucutre when possible.
3 people like thisPosted: 2 months ago by Tomas Petricek