Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3630680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:18:03+00:00 2026-05-19T00:18:03+00:00

This is quite simple question but I didn’t find an answer: Is there any

  • 0

This is quite simple question but I didn’t find an answer:

Is there any Seq/List operation in F# to match the LINQ SelectMany?

  • I know I can use System.Linq in F# if I
    want to.
  • I know I can make a recursive method
    and use F# Computation Expressions
    (and make even more powerful things).

But if I try to prove that F# List operations are more powerful than LINQ…

  • .Where = List.filter
  • .Select = List.map
  • .Aggregate = List.fold
  • …

In C# SelectMany usage syntax is pretty simple:

var flattenedList = from i in items1
                    from j in items2
                    select ...

Is there any easy direct match, List.flatten, List.bind or something like that?

SelectMany has a couple of signatures, but the most complex one seems to be:

IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(
    this IEnumerable<TSource> source, 
    Func<TSource, IEnumerable<TCollection>> collectionSelector, 
    Func<TSource, TCollection, TResult> resultSelector
);

In F# terms this would be:

('a -> 'b list) -> ('a -> 'b -> 'c) -> 'a list -> 'c list
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:18:04+00:00Added an answer on May 19, 2026 at 12:18 am

    collect is the F# equivalent of SelectMany however it doesn’t provide all the overloads. Here’s how to make the one you referenced.

    let selectMany (ab:'a -> 'b seq) (abc:'a -> 'b -> 'c) input =
        input |> Seq.collect (fun a -> ab a |> Seq.map (fun b -> abc a b))
    // gives
    // val selectMany : ('a -> seq<'b>) -> ('a -> 'b -> 'c) -> seq<'a> -> seq<'c>
    

    I believe F# doesn’t provide all the SelectMany overloads because they would add noise to the library. Here’s all four overloads to SelectMany in Microsoft Naming.

    let selectMany (source : 'TSource seq) (selector : 'TSource -> 'TResult seq) =
        source |> Seq.collect selector
    
    let selectMany (source : 'TSource seq) (selector : 'TSource -> int -> 'TResult seq) =
        source |> Seq.mapi (fun n s -> selector s n) |> Seq.concat
    
    let selectMany (source : 'TSource) 
                   (collectionSelector : 'TSource -> 'TCollection seq)
                   (resultSelector : 'TSource -> 'TCollection -> 'TResult) =
        source 
        |> Seq.collect (fun sourceItem -> 
            collectionSelector sourceItem 
            |> Seq.map (fun collection -> resultSelector sourceItem collection))
    
    let selectMany (source : 'TSource) 
                   (collectionSelector : 'TSource -> int -> 'TCollection seq)
                   (resultSelector : 'TSource -> 'TCollection -> 'TResult) =
        source 
        |> Seq.mapi (fun n sourceItem -> 
            collectionSelector sourceItem n
            |> Seq.map (fun collection -> resultSelector sourceItem collection))
        |> Seq.concat
    

    “F# List operations are more powerful than LINQ…” While seq / list operations are great some real “F# power” comes from Function Composition and Currying.

    // function composition
    let collect selector = Seq.map selector >> Seq.concat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One simple question (but I haven't quite found an obvious answer in the NLP
a simple question but Ive realised im not sure of the answer for this
I guess this is a quite simple (read: very simple) question, but I have
Hey guys, This could be a noob question, but I really can't find any
I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
Ok, didn't really want to ask this question as it should be quite a
This sounds like a simple question, but I don't know how to search for
Sorry, but I tried searching for this subject, but I didn't find related to
I am aware of both this and this questions. Which unfortunately didn't quite answer
This is a very simple question for many of you reading this, but it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.