Snippets tagged sequences

  • Palindromic dates

    Today, 11. february 2011, is a palindromic day according to the European date format (day/month/year). This snippet collects all the palindromic dates until 31 dec. 9999. They are 366, a surprisingly low number.

    13 people like this

    Posted: 9 years ago by Francesco De Vittori

  • Extensions to the Fold function

    This snippet is helpfull in the following cases: 1) After a consolidation operation using the fold function we need to know how many elements have been processed. 2) A consolidation operation needs to use the index of each of the elements processed and we don't want to use the mapi function first. 3) A combination of the above. Since the following snippet just adds a wrapper to the existing Fold function we can repeat the approach for arrays and sequences (including the plinq ones)

    31 people like this

    Posted: 9 years ago by Horacio Nuñez

  • Lazy String

    Lazy string based on seq

    4 people like this

    Posted: 9 years ago by Ankur Dhama

  • Partition a sequence into groups linearly by predicate

    Partitions a sequence into groups linearly by predicate. I use this for breaking up my lazy record parsing with sequences into entity-sized chunks which are then easily digestible. Note: Edited back from the previous edit as these were heavily profiled and yield! tends to be slow. Edit #2: Now correctly using "use" instead of "let" for sequence.GetEnumerator () (Thanks Vladimir Matveev)

    1 people like this

    Posted: 9 years ago by Rick Minerich

  • Moving Average

    Given a period and a sequence of values, calculates the moving average of the input. E.g., given a period of 4 and a sequence of { 2.0, 8.0, 12.0, 10.0, 6.0, 4.0, 14.0 }, the result of this function is { 8.0, 9.0, 8.0, 8.5 }.

    8 people like this

    Posted: 9 years ago by Brett V. Forsgren

  • All subsets of a set

    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.

    10 people like this

    Posted: 8 years ago by Tomas Petricek

  • Soundex Algorithm

    Algorithms for generating US Census and Daitch-Mokotoff soundex string(s) based on a text input. Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling.

    4 people like this

    Posted: 8 years ago by Matt Wilson

  • Finding matching pairs in two sequences

    Here's a function which takes a comparator function and two sequences, and returns tuples consisting of an item from each sequence, where the comparator function returns true for those two items. This is a small part of my wider project to generate guitar chord shapes. One of the requirements there is to take a list of 'wanted' notes for a chord, and a list of 'available' notes within a range of frets and to combine them into an actual set of frettings. That's what led to tryFindFirstPair and hence to findPairs.

    1 people like this

    Posted: 8 years ago by Kit Eason

  • Calculating when the 1000th XKCD will appear

    Calculate's when a the nth XKCD will appear, starting from XKCD 946. For a full explanation this snippet see: http://strangelights.com/blog/archive/2011/09/02/calculating-when-the-1000th-xkcd-will-appear.aspx

    3 people like this

    Posted: 8 years ago by Robert Pickering

  • Seq.groupAfter function

    This snippet is basically the same as http://fssnip.net/6A, except that the element whose predicate holds ends the previous group and the element after it starts a new one. Those two snippets (Seq.groupWhen, Seq.groupAfter) would be generally equivalent to the Haskell functions 'breakBefore' and 'breakAfter' from Data.List.Grouping.

    0 people like this

    Posted: 8 years ago by Thorsten Meinecke

  • Take a sample of a sequence

    Take a sample of a specified length from a sequence. The sample is guaranteed to be of the requested size (unless there are too few elements in the original sequence). Sample items will be taken at equal intervals. (This version with some simplifications and tidy-ups.)

    0 people like this

    Posted: 8 years ago by Kit Eason

  • tryNth

    Computes the nth value of a sequence if the nth value is past the length of the sequence then None is returned else some

    3 people like this

    Posted: 8 years ago by Colin Bull

  • Simple single-server queue simulation

    Simulation and performance measurement of a single-server queue with various arrival and processing rates configurations. More comments on this can be found at http://www.clear-lines.com/blog/post/Simulating-a-simple-Queue-in-FSharp.aspx

    5 people like this

    Posted: 7 years ago by Mathias Brandewinder

  • Undertone: First line of Baa baa black sheep

    Playing with Undertone, using operators for terse tune definitions.

    1 people like this

    Posted: 7 years ago by Michael Newton

  • Sequence of all Subsets of a set

    A function that returns a sequence of subsets generated by the power set of a specified set. The function use bit patterns to generate sets. for example the power set generated by a set with 3 elements set [1;2;3;] has 2^3 sets. each set in the power set is represented by the set bits in each of the integer from 0 to (2^3) -1

    8 people like this

    Posted: 7 years ago by isaiah perumalla

  • Implement a suppression list

    Take a sequence and exclude values from it based on another 'suppression list' sequence.

    1 people like this

    Posted: 7 years ago by Kit Eason

  • hexdump (somewhat fast)

    Simple functions to display a hex dump of a byte array using sequence expressions, with ASCII. Rewrote naive version that used string concat, based on optimizations in http://fssnip.net/ht, and cleaned up ASCII formatting.

    2 people like this

    Posted: 7 years ago by Matthew H. Traylor

  • Course 3: Exploring Titanic dataset

    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 this

    Posted: 6 years ago by Tomas Petricek

  • Generating a tree from a generic type

    I needed a function to generate a tree from a c# class that had some odd semantics, but when I refactored it, I realised almost everyone must have something similar knocking around their codebase, so here's mine.

    0 people like this

    Posted: 6 years ago by Sean Newham

  • BitArray to Sequence

    Convert a BitArray to a sequence.

    1 people like this

    Posted: 6 years ago by Samuel Bosch

  • Faster .. operator for range generation

    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 this

    Posted: 4 years ago by Tomas Petricek

  • Seq.groupWhen function

    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 this

    Posted: 3 years ago by Tomas Petricek

  • Generate a date range sequence (another alternative)

    Generates a sequence of dates (ascending or descending), incrementing (or decrementing) by one day at a time, inclusive of the start and end dates. This is an alternative to http://www.fssnip.net/oS

    5 people like this

    Posted: 2 years ago by Fernando Saldanha

  • Very Fast Permutations

    I spent a lot of time this week profiling different permutation functions from various places on the internet. The following was by far the fastest:

    4 people like this

    Posted: 4 months ago by Rick Minerich