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

  • SEARCH
  • Home
  • 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 7706575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:09:33+00:00 2026-06-01T00:09:33+00:00

I have a nested dictionary Map<‘a,Map<‘b,’T>> , so that for a combination of a*b

  • 0

I have a nested dictionary Map<'a,Map<'b,'T>>, so that for a combination of a*b, the entry is unique.

In order to precompute efficiently, I would need to invert the keys in a Map<'b,Map<'a,'T>>

I have some higher order methods that do the job (|/> will apply the operation in a nested sequence |//> the same, but 2 levels deep, |*> will enumerate the cartesian product of nested sequence), but I am wondering if there is a better way to do this, just in case there is beautiful code to share on this one.

let reversenmap (x:Map<'a,Map<'b,'T>>) :Map<'b,Map<'a,'T>> = 
      let ret  = x |> Map.toSeq |/> Map.toSeq |*> squash12
      let ret2 = ret |> Seq.groupByn2 (fun (a,b,t) -> b) 
                                      (fun (a,b,t) -> a) |//> Seq.head 
                                                         |//> (fun (a,b,c) -> c)
      ret2 |> Seq.toMapn2
  • 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-01T00:09:34+00:00Added an answer on June 1, 2026 at 12:09 am

    I think the solution from @pad is definitely more idiomatic F# than using non-standard operators like |/> and |*>. I would probably prefer a version that uses sequence expressions instead of Seq.collect, which looks like this (the second part is the same as in the version from @pad):

    let reverse (map: Map<'a,Map<'b,'T>>) = 
      [ for (KeyValue(a, m)) in map do
          for (KeyValue(b, v)) in m do yield b, (a, v) ]
      |> Seq.groupBy fst 
      |> Seq.map (fun (b, ats) -> b, ats |> Seq.map snd |> Map.ofSeq) 
      |> Map.ofSeq 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that consists primarily of a very large nested dictionary: class
I have the following nested dictionaries: Dictionary<int, Dictionary<string, object>> x; Dictionary<int, SortedDictionary<long, Dictionary<string, object>>>
Suppose I have a dictionary, and it's nested with dictionaries inside. I want to
I keep finding that if I have nested divs inside each other, and one
I have some nested tables that I want to hide/show upon a click on
I have some deeply randomly nested dictionary as follows. {'CompilationStatistics': {'CodeGeneration': {'EndTime': '2010-04-21T14:03:11', 'StartTime':
I'm stumped. I have an NSMutableDictionary w/ nested dictionaries that I am enumerating through
I have a nested dictionary of type following {id_1 : [ {id_2:score},{id_3:score_2} .... and
I have a array with nested dictionary data like this: [{ link : [
I have a structure that can be very easily represented using a three-deep nested

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.