Demonstrates how to use unfold to create an infinite list of the fibonacci numbers
56 people like thisPosted: 7 years ago by Robert Pickering
Implements iterate function from Haskell's Prelude. The function generates an infinite sequence by applying a function to the initial value (first) and then to the result of previous application.
203 people like thisPosted: 7 years ago by Nick Palladinos
An asynchronous sequence is similar to the seq
Posted: 7 years ago by Tomas Petricek
Cached fib sequence
14 people like thisPosted: 7 years ago by Dmitri Pavlenkov
A more tolerant and open-minded take.
18 people like thisPosted: 7 years ago by Dan Finch
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.
30 people like thisPosted: 7 years ago by Tomas Petricek
Abstracts console input as an infinite sequence of lines of text
7 people like thisPosted: 6 years ago by fholm
.Net 4.0 added File.ReadLines to view a file as a sequence, but the sequence can only be read once. A simple wrapper with seq{yield!} fixes that.
43 people like thisPosted: 6 years ago by Tony Lee
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 thisPosted: 6 years ago by Rick Minerich
A partition function on sequences, like List.partition and Array.partition, but yields elements in either partition on demand. Suitable as an extension to Seq.
4 people like thisPosted: 6 years ago by Stephen Swensen
Generates a sequence using a sequence generator and Async.StartWithContinuations. This is an attempt at modeling the OWIN delegate structure in F#
5 people like thisPosted: 6 years ago by Ryan Riley
Euler #5 solution
3 people like thisPosted: 6 years ago by Michael Falanga
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 thisPosted: 6 years ago by Thorsten Meinecke
A pattern for creating n-ary Seq.map functions.
3 people like thisPosted: 6 years ago by Nick Palladinos
seq to IEnumerator and IEnumerable
2 people like thisPosted: 5 years ago by Graham Spiers
Applying functions on the n first elements
1 people like thisPosted: 5 years ago by Nicolas2
This function splits a sequence into lists of length n until there is less than n elements then those are returned.
4 people like thisPosted: 5 years ago by Taha Hachana
Peeks from a few seq randomly according to specified frequencies. not tested
2 people like thisPosted: 4 years ago by nicolas2
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.
4 people like thisPosted: 4 years ago by Samuel Bosch
A variation of another snippet "Seq.groupWhen". This one groups adjacent elements based on a predicate that accepts two arguments - the previous and current elements
5 people like thisPosted: 3 years ago by Faisal Waris
Generates a sequence of dates (ascending or descending), incrementing (or decrementing) by one day at a time, inclusive of the start and end dates.
3 people like thisPosted: 3 years ago by Daniel Bradley
Yet Another Fizz Buzz (YAFB)
8 people like thisPosted: 2 years ago by @Functional_S
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: 1 year ago by Tomas Petricek
a) Organize a sequence into a table of aggregations by rows and columns. b) convert raw crosstab data into a DataTable
4 people like thisPosted: 5 months ago by Faisal Waris
A generic function that randomly permutes the elements of a sequence.
0 people like thisPosted: 3 months ago by Taha Hachana
Show's using the unfold function to create a sequence that terminates once some limit is passed.
37 people like thisPosted: 7 years ago by Robert Pickering
Computes the Cartesian product of a sequence of sequences. See corresponding example for a list of lists.
46 people like thisPosted: 7 years ago by Neil Carrier
I'm working on parallel computations and I thought it would be useful to break work into chunks, especially when processing each element asynchronously is too expensive. The neat thing is that this function is general even though motivation for it is specific. Another neat thing is that this is true lazy sequence unlike what you'd get if you used Seq.groupBy. There are three versions for your enjoyment.
70 people like thisPosted: 7 years ago by Dmitri Pavlenkov
This function is given a partition predicate and a sequence. Until the predicate returns false, a list will be filled with elements. When it is, both the list and the remainder of the sequence will be returned. Note that this example preserves the laziness of the unchecked sequence elements.
68 people like thisPosted: 7 years ago by Rick Minerich
Function to generate circular infinite sequence from a list
18 people like thisPosted: 7 years ago by Ankur Dhama
Randomizes order of specified sequence
22 people like thisPosted: 6 years ago by Phillip Trelford
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: 6 years ago by Tomas Petricek
A broken code example demonstrating how it's you can't catch a single throwing enumeration and continue with F#'s IEnumerable.
2 people like thisPosted: 6 years ago by Rick Minerich
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:
13 people like thisPosted: 6 years ago by Rick Minerich
Triple version of Seq.pairwise.
2 people like thisPosted: 6 years ago by ptan
Take value from a sequence only when it changes (based on a predicate). Ex: Seq [1;1;1;3;3;3;5;5;5] will result in [3;5]
0 people like thisPosted: 6 years ago by Ankur Dhama
The snippet shows a parser for command-line arguments supporting value lists for single commands. Calling with the following arguments: "Arg 1" "Arg 2" -test "Case 1" "Case 2" -show -skip "tag" produces the following map: map [("", seq ["Arg 1"; "Arg 2"]); ("show", seq []); ("skip", seq ["tag"]);("test", seq ["Case 1"; "Case 2"])] which can be used to find what data have been sent along with different commands. Calling with the following: "Arg 1" "Arg 2" /test="Case 1" "Case 2" --show /skip:tag produces the same result.
5 people like thisPosted: 6 years ago by Gennady Loskutov
A function that takes a random subset from a seq<'T>.
0 people like thisPosted: 6 years ago by Taha Hachana
A pattern for creating n-ary Seq.map functions, based on numerals.
4 people like thisPosted: 6 years ago by Nick Palladinos
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.
5 people like thisPosted: 5 years ago by Tomas Petricek
This snippet defines a computation builder that sums the squares of float values. It includes Combine, Zero, Yield, Delay, and For operations.
2 people like thisPosted: 5 years ago by Joel Huang
A generalised version of the solution to the fourth Project Euler problem - Largest palindrome product, using sequences. The key to understanding this code is how "Seq.map (fun x -> (Seq.map (fun y -> x * y) baseSeq)) baseSeq" generates a sequence of sequences that contains the products of all possible combinations of two n-digit numbers. "Seq.map (fun x -> (Seq.map (fun y -> x * y) {1..3})) {1..3}" will generate: seq [seq [1; 2; 3]; seq [2; 4; 6]; seq [3; 6; 9]]
0 people like thisPosted: 4 years ago by Bjørn Bæverfjord
A version of mapi for very long sequences that uses long integers instead of regular integers. I didn't use a mutable variable because of this http://stackoverflow.com/questions/1480582/the-mutable-variable-i-is-used-in-an-invalid-way
4 people like thisPosted: 4 years ago by Samuel Bosch
Convert a BitArray to a sequence.
1 people like thisPosted: 4 years ago by Samuel Bosch
Creates a map containing each item and its frequency as a key/value pair. Then sort by value in reverse order before printing each item.
1 people like thisPosted: 3 years ago by Bjørn Bæverfjord
Fibonacci sequence with scan
4 people like thisPosted: 2 years ago by Andriy Tolstoy
Functional and simple version for Collatz Conjecture or 3n + 1 Problem
5 people like thisPosted: 1 year ago by Fabio Galuppo
This function takes an input sequence and returns a function that returns the elements in the sequence one by one when called consecutively. The returned function will throw if called more times than there are elements in the sequence. Useful when unit testing.
3 people like thisPosted: 1 year ago by Peder Sørensen
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
2 people like thisPosted: 4 months ago by Fernando Saldanha
This sample show how to use seq-yield syntax to convert a binary tree to a sequence of elements.
3 people like thisPosted: 3 months ago by Dmitry Soshnikov