## Snippets tagged sequence

• ### Largest Palindrome Number from Product of Two Three Digit Numbers

Here is an improved version twice shorter, than original

72 people like this

Posted: 13 years ago by Nick Canzoneri

• ### EnumerableStream

A lazy enumerable/stream of bytes.

9 people like this

Posted: 13 years ago by Ryan Riley

• ### Function to generate circular infinite sequence from a list

Function to generate circular infinite sequence from a list

20 people like this

Posted: 13 years ago by Ankur Dhama

• ### Gaussian Random Sequence

Normalized Random sequence generator conforming to the user supplied mean and sigma utilizing a "seed factory" instead of the default time of day. The Gaussian sequence is based on the central limit theory, averages together the flat distribution from the random generator built into .NET. Two examples of using normalRand are given to create infinite sequences of white and brown(ian) noise.

45 people like this

Posted: 13 years ago by Tony Lee

• ### Tree using sequences

Tree implementation using sequences.

2 people like this

Posted: 13 years ago by Ankur Dhama

• ### Select n elements in group from seq

Select n elements in group from seq

2 people like this

Posted: 13 years ago by Ankur Dhama

• ### Repeat until

Repeatedly call a function until it returns a positive result. Implemented using sequences.

3 people like this

Posted: 13 years ago by Johann Deneux

• ### ByteString

An initial attempt at creating a ByteString type based on the Haskell version.

4 people like this

Posted: 13 years ago by Ryan Riley

• ### Seq.reduceBallanced function

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 this

Posted: 12 years ago by Tomas Petricek

• ### Partition a list

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 this

Posted: 11 years ago by Tomas Petricek

• ### Primes

Generates the Prime Number Sequence.

1 people like this

Posted: 11 years ago by AdamSpeight2008

• ### Cartesian product in sequence expression

Sequence expression which deals with cartesian product of sequences with for ... do expression. It replaces nested for .. do expression to single one.

0 people like this

Posted: 10 years ago by nagat01

• ### Splitting a sequence based on separator condition

Whilst working on a google API wrapper, I came across the need to separate a sequence into sub-sequences based on a separator condition. This also led to a requirement for versions of takeWhile and skipWhile which also include the element which first breaks the condition predicate.

3 people like this

Posted: 10 years ago by Chris Ballard

• ### Treat a sequence as a circular sequence

Create a circular (repeating) sequence from an input sequence, optionally limiting the total number of elements.

0 people like this

Posted: 8 years ago by Hugh Gleaves

• ### Collapse a sequence

Eliminate repetitions in a sequence, preserving the first element in each run of repeats.

2 people like this

Posted: 6 years ago by Kit Eason

• ### Continue sequence after applying Seq.takeWhile, skip, take, etc

Sometimes you need to take more elements from a sequence, e.g. look at https://stackoverflow.com/questions/12562327/how-to-do-seq-takewhile-one-item-in-f This solution allows fetching elements from the same sequence after applying takeWhile, skip, take and other sequence functions. However, need to remember to call function with right parameter: use 'true' to include current element into result sequence (after takeWhile for example)

2 people like this

Posted: 4 years ago by Ruslan Enikeev

• ### Asynchronous sequences

An asynchronous sequence is similar to the seq type, but the elements of the sequence are generated asynchronously without blocking the caller as in Async. This snippet declares asynchronous sequence and uses it to compare two files in 1k blocks.

109 people like this

Posted: 13 years ago by Tomas Petricek

• ### Fibonacci sequence

Cached fib sequence

15 people like this

Posted: 13 years ago by Dmitri Pavlenkov

• ### Take every Nth element of sequence

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 this

Posted: 13 years ago by Tomas Petricek

• ### Chronological sequence window beginnings

An abstraction of the following use case: Given a sequence of dates and max temperatures for each date, extract out the initial dates on which the temp is greater than a given threshold for n consecutive days. (Originally posted as an answer to this StackOverflow question: http://stackoverflow.com/questions/5267055 )

13 people like this

Posted: 13 years ago by ildjarn

• ### exec with redirected io as sequences

Since F# is my new scripting language, I needed something like Perl's exec but with sequences for Std In and Out.

7 people like this

Posted: 13 years ago by Tony Lee

• ### Incremental (Functional) QuickSort

Functional quicksort inspired by the Haskell Quick Sort at http://www.haskell.org/haskellwiki/Introduction. Since F# lists aren't lazy, uses sequences instead of lists to be haskell like. Roughly O(n) if you Seq.take 1, full on QS if you enumerate the whole thing.

3 people like this

Posted: 13 years ago by Tony Lee

• ### Seq group continuous matching elements

Seq group continuous matching elements [1;1;1;2;2;2] will become [ [1;1;1] ; [2;2;2] ]

2 people like this

Posted: 13 years ago by Ankur Dhama

• ### Splice sequence into other sequence

Splices a sequence into another sequence at a specified index n. Can replace the existing element at n or keep it.

3 people like this

Posted: 12 years ago by Henrik Ravn

• ### Nest items of a sequence

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 this

Posted: 12 years ago by Tomas Petricek

• ### Enumerable extraction in query expressions

Adds "enumerable extraction" support to query expressions

7 people like this

Posted: 11 years ago by kvb

• ### The Dominator of Array

The dominator of array A is the value that occurs in more than half of the elements of A. It is a zero-indexed based array consisting of N integers (A [] with N length). To find the index array of the dominator from a A [], we can use a helpful function from Seq module call 'Seq.groupBy' to mitigate the implementation of a solution.

4 people like this

Posted: 11 years ago by Joel Huang

• ### Convert list of sequences to sequence of lists

Function to combine the values of a list of sequences into a sequence of lists where each list contains the nth element of the different sequences. It works like zip but for an arbitrary number of sequences and it returns lists instead of tuples. As with zip when one sequence is exhausted any remaining elements in the other sequences are ignored.

5 people like this

Posted: 10 years ago by Samuel Bosch

• ### Decoder for Google API polylines

Full source code for my blog entry on this subject - http://chrsb.co/BNqAbM

1 people like this

Posted: 10 years ago by Chris Ballard

• ### Sequence Random Permutation

A generic function that randomly permutes the elements of a sequence.

0 people like this

Posted: 6 years ago by Taha Hachana

• ### Exponentiation by squaring

Function, what calculates x^n by non-recursive basic exponentiation squaring algorithm. This method uses the bits of the exponent to determine computing powers. Generic parameter x suitable for any type what supports multiplication. I do not suppose existence of inverse operator like "/", thus parameter n must be a positive integer only. It is not difficult to define an extended variant for a type what supports division.

3 people like this

Posted: 4 years ago by Pavel Tatarintsev