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 8416933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:54:21+00:00 2026-06-10T01:54:21+00:00

I am trying to work with SharePoint 2010 objects with F# (just as experiement).

  • 0

I am trying to work with SharePoint 2010 objects with F# (just as experiement).

So I write this code

let getSPDomainUsers (spWeb : SPWeb) =
seq {
  for r in spWeb.RoleAssignments do
    match r.Member with
    | :? SPUser as user ->        
      for b in r.RoleDefinitionBindings do
        if (user.IsDomainGroup) then yield (spWeb.Url.ToLower(), user, b.Name.ToLower())
    | :? SPGroup as group ->
      for u in group.Users do
        for b in r.RoleDefinitionBindings do
          if (u.IsDomainGroup) then yield (spWeb.Url.ToLower(), u, b.Name.ToLower())
    | _ -> ()
} 

However with all these for loops and if conditions my code looks very imperative.

instead of for loop I want to do something like List.map However most of these objects like
RoleDefinitionBindings or RoleAssignments are returning me Collections which are not Lists or Arrays or Sequences so I am forced to write loops.

Can you tell me a way in which I can avoid the loops when the return type is a custom collection object like SPRoleAssignmentCollection and SPRoleDefinitionBindingCollection.

  • 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-06-10T01:54:23+00:00Added an answer on June 10, 2026 at 1:54 am

    SPRoleDefinitionBindingCollection inherits SPBaseCollection which implements IEnumerable (but not IEnumerable<T>, i.e., seq<'T>). You can use Seq.cast to convert instances of IEnumerable into a seq<'T>.

    Once you have a seq<'T> you can use the usual functions in the F# Seq module.

    Here’s a cleaned-up version of your code. I don’t have SharePoint so I can’t compile/test it; you may need to explicitly cast the custom collection types to IEnumerable before piping them into Seq.cast.

    let userInfo (user : SPUser) =
        user.RoleDefinitionBindings
        |> Seq.cast<SPRoleDefinition>
        |> Seq.choose (fun b ->
            if user.IsDomainGroup then
                Some (spWeb.Url.ToLower(), user, b.Name.ToLower())
            else None)
    
    let getSPDomainUsers (spWeb : SPWeb) =
        spWeb.RoleAssignments
        |> Seq.cast<SPRoleAssignment>
        |> Seq.collect (fun r ->
            match r.Member with
            | :? SPUser as user ->
                userInfo user
            | :? SPGroup as group ->
                Seq.collect userInfo group.Users
            | _ ->
                Seq.empty)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out how to get sharepoint 2010 to display the quicklaunch
All, I am trying to make the width of the sharepoint 2010 web site
I need the community's help on this. We have TFS 2010 and SharePoint services
We are deploying sharepoint MOSS 2007 at our work. I'm trying to come up
I'm trying to make a site map for a Sharepoint 2010 that will list
I'm trying to build a custom activity for SharePoint 2010 to be used in
This has been frustrating me for days now. I am trying to use Sharepoint
This code used to work in WSS 3.0 / MOSS 2007 in FeatureReceiver.FeatureActivated: using
I'm trying to develop some SharePoint workflows for the company I work for, and
I am trying to make improvements to a SharePoint 2010 site and am running

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.