Snippets tagged fold

  • 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

  • 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: )

    13 people like this

    Posted: 9 years ago by ildjarn

  • Folding over prime factors

    Let's have some fun with higher order functions and instead of folding over a list, fold over the prime factors of a number. It can be optimized further by dividing out real primes instead of numbers of the form 6k+/-1, but it's not embarrassingly slow.

    2 people like this

    Posted: 8 years ago by Arjen Kopinga

  • Successive fold functions

    fold by applying a list of function to a list of arg, last one behaving as usual

    1 people like this

    Posted: 7 years ago by nicolas2

  • Array Shuffle

    Shuffling array using Seq.fold

    4 people like this

    Posted: 6 years ago by Karlkim Suwanmongkol

  • Convert booleans to bits using fold

    @Samuel - saw your post and thought one part was similar to bit shifting I was playing with yesterday, so rewrote the FromBooleans function using a fold instead of ref cells. Probably not as readable as your version though :)

    2 people like this

    Posted: 5 years ago by Chris Ballard

  • Parallel fold

    Idea from Guy L. Steele - Organizing Functional Code for Parallel Execution; or, foldl and foldr Considered Slightly Harmful -

    9 people like this

    Posted: 5 years ago by Tuomas Hietanen

  • Type-level Fold

    Generic Type-level Fold for Boolean Algebra

    0 people like this

    Posted: 4 years ago by Nick Palladinos

  • SIMD fold extension for Array

    A SIMD enhanced fold function that adds on to the Array type

    2 people like this

    Posted: 3 years ago by Jack Mott

  • Project Euler #1

    This snippet is code that solves first Project Euler problem. It finds the sum of all the multiples of 3 or 5 below 1000. Please add other (more efficient, succinct or interesting) solutions to this snippet.

    1 people like this

    Posted: 6 months ago by Eugene Gavrin