Snippets tagged list

  • Filtering lists

    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.

    39 people like this
    Posted: 1 years ago by Tomas Petricek

  • Pipeline list processing

    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.

    76 people like this
    Posted: 1 years ago by Tomas Petricek

  • Association list lookup

    While prototyping programs I find myself using association lists. This little snippet defines a lookup functions for association lists defined as lists of tuples.

    47 people like this
    Posted: 1 years ago by Alex Muscar

  • 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.

    37 people like this
    Posted: 1 years ago by Eugene Gavrin

  • Cartesian Product of Lists

    Computes the Cartesian product of a list of lists. See also corresponding example for a sequence of sequences.

    34 people like this
    Posted: 1 years ago by Neil Carrier

  • Projecting lists

    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.

    43 people like this
    Posted: 1 years ago by Tomas Petricek

  • Function to get all possible combinations

    Function to get all possible combinations of list items. There are some Euler problems (like 77 & 78) to get total amounts. But e.g. for some card game implementations you will need the real items.

    27 people like this
    Posted: 1 years ago by Tuomas Hietanen

  • Function to generate all possible combinations where combination "ab" != "ba"

    Function to generate all possible combinations where combination "ab" is different then "ba"

    5 people like this
    Posted: 1 years ago by Ankur Dhama

  • Remove first ocurrence from list

    Removes from list the first ocurrence only of an element that satisfies the predicate. Additional elements that also satisfy the predicate remain in the list.

    32 people like this
    Posted: 1 years ago by Alexander Rautenberg

  • Partition a sequence until a predicate is satiated

    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.

    38 people like this
    Posted: 1 years ago by Rick Minerich

  • All combinations of list elements

    For a given list, find all possible combinations of elements of the list (not just k-combinations). The result is a list of lists with each element representing one combination. Order of elements is not taken into account.

    14 people like this
    Posted: 1 years ago by Alexander Rautenberg

  • Cartesian product of n lists

    Cartesian product of a variable number of lists. Input is a list of lists of which the cartesian product is to be constructed; output is a list that contains the elements of the product set, as lists.

    11 people like this
    Posted: 1 years ago by Alexander Rautenberg

  • Split a list

    Three ways to split a list in half (but not necessarily in the middle). A forth version added that's very short and should be fast, as we only use List.fold. New champ found.

    48 people like this
    Posted: 1 years ago by Dmitri Pavlenkov

  • Permutations

    computes the list of all permutations of a list for example the permutations of [1;2;3] will be [1;2;3]; [1;3;2]; [2;1;3]; [2;3;1]; [3;1;2]; [3;2;1]

    2 people like this
    Posted: 1 years ago by Carsten König

  • 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: 1 years ago by Rick Minerich

  • Python's sorted function

    This is an attempt to produce similar behavior as seen in the sorted( ) function in Python. Supporting only one of the three optional arguments. The key - Specifies a function of one argument that is used to extract a comparison key from each list element

    2 people like this
    Posted: 1 years ago by Cameron Frederick

  • Hughes's FuncList

    A FuncList is a "list-like" datatype with constant time append (represented as a function of cons-lists). The implementation is based on a convenient computation builder.

    1 people like this
    Posted: 11 months ago by Nick Palladinos

  • Hughes's CPSFuncList

    A CPS version of FuncList, in order to avoid blowing the stack.

    3 people like this
    Posted: 11 months ago by Nick Palladinos

  • String explode and implode

    Convert string to and from character lists.

    3 people like this
    Posted: 11 months ago by petebu

  • ByteString

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

    1 people like this
    Posted: 10 months ago by Ryan Riley

  • Pack consecutive duplicates of list elements into sublists

    Pack consecutive duplicates of list elements into sublists.If a list contains repeated elements they should be placed in separate sublists.

    0 people like this
    Posted: 8 months ago by Naveen

  • Random Subset

    A function that takes a random subset from a seq<'T>.

    0 people like this
    Posted: 5 months ago by Taha Hachana

  • 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: 4 months ago by Tomas Petricek

  • Remove duplicate list elements

    Remove duplicate elements of a list. Returns list with first instance of duplicate elements, without modification of order except subsequent duplicate elements are omitted.

    1 people like this
    Posted: 2 months ago by visProcessEngg