I have this code
let inline ProcessExpendableADGroups (input : ('a * SPUser) seq) =
input
|> Seq.filter (fun (_, u : SPUser) -> u.IsDomainGroup = true)
|> Seq.filter (fun (_, u : SPUser) -> ADUtility.IsADGroupExpandable u.LoginName = true)
|> List.ofSeq
|> List.iter(
fun ( li : 'a, u : SPUser) ->
let userList = ADUtility.GetUsers u.LoginName
if (Seq.length userList <= 500) then
userList
|> Seq.filter (fun l -> InfobarrierPolicy.IsUserInPolicy l "FW" = true)
|> Seq.iter (
fun ln ->
let x = ADUtility.GetNameAndEmail ln
let (email, name) = x.Value
SPUtility.CopyRoleAssignment li u.LoginName ln email name
li.Update()
)
SPUtility.RemoveRoleAssignment li u
)
list3
|> List.iter (
fun w ->
SPUtility.GetDirectAssignmentsforListItems w |> ProcessExpendableADGroups
SPUtility.GetDirectAssignmentsforFolders w |> ProcessExpendableADGroups
SPUtility.GetDirectAssignmentsforLists w |> ProcessExpendableADGroups
SPUtility.GetDirectAssignmentsforWeb w |> ProcessExpendableADGroups
)
Here the methods GetDirectAssignmentsforListItems returns a Sequence of tuples (SPListItem * SPUser)
GetDirectAssignmentsforWeb returns a sequence of tuples (SPWeb * SPUser).
I need to send this sequence to a function which does very similar processing on these items except that in the end I have to call a method called “Update” on these items.
I have written a method with Generic parameter but I am having a problem when I call Update on the generic parameter.
I am not able to constrain this parameter to say that the parameter must have a method called Update.
You can use member constraints and statically resolved type parameters to do so.
There is also a series of helpful articles on the topic here.
A few improvements I have done on the function above:
Seq.filtercould be collapsed to oneSeq.filter, and= trueis always a code smell.List.ofSeqandList.itercould be replaced bySeq.iter. When you useSeq.iter, a lazy sequence will be evaluated anyway.li: 'aandu: SPUser. Since you use piping and have type annotation forinput, the type checker would be able to infer correct types.