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

The Archive Base Latest Questions

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

I would like to implement a map from selected objects to property entries in

  • 0

I would like to implement a map from selected objects to property entries in property editor. For example like in Visual Studio xaml editor.

The target map is something like this (or maybe using ReactiveCollection from ReactiveUI?)

 Selected objects             Filled categories to display in PropertyEditor  
 -------------------------    ---------------------------------------
 ObservableCollection<obj> -> ObservableCollection<Category>

The map in plain English:

  1. Collect all unique property types from objects
  2. Group by category (e.g. Text, Layout)
  3. Add/Remove categories as necessary to reflect selected objects
  4. Add/Remove properties from existing categories as necessary

The challenge is to have declarative/functional code without add/remove branches. (I do already have an imperative/event based code which is quite ugly and error prone.)

I think we could assume that Category and Property collections are sets with the usual operations: Union, Substract, and IsMember.

The inspiration is the code from ReactiveUI by Paul Betts which is beatiful for simple one-to-one map:

var Models = new ReactiveCollection<ModelClass>();
var ViewModels = Models.CreateDerivedCollection(x => new ViewModelForModelClass(x));
// Now, adding / removing Models means we
// automatically have a corresponding ViewModel
Models.Add(new Model(”Hello!”));
ViewModels.Count();
>>> 1

Using Seq and F# the straightforward nonobservable map would look like this:

selectedObjects
|> Seq.collect GetProperties |> Seq.unique |> Seq.groupBy GetPropertyCategory
|> Seq.map (fun categoryName properies -> CreateCategory(properties))

The above code is fine in theory but in practice it would recreate all the view models from scratch on each change in selected objects. What I would love to achieve with Rex is to have the version of the above map with incremental updates, so the WPF will update only the changed parts of the GUI.

  • 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-10T05:54:51+00:00Added an answer on June 10, 2026 at 5:54 am

    This is a very interesting problem :-). Sadly, I don’t think there is any F# library that allows you to solve that easily. As far as I can tell, Bindable LINQ was one attempt to implement LINQ query pattern (i.e. Select, SelectMany and Where methods) for ObservableCollection<T>, which is essentially what you need. To use it from F#, you could wrap LINQ operations in functions like map etc.

    As you say, functions like Seq.map work by on IEnumerable and so they are not incremental. What you’d need here are functions like map, filter and collect, but implemented over ObservableCollection<'T> in such a way that they do the changes incrementally – when new element is added to the source collection, the map function would process it and add a new element to the resulting collection.

    I experimented with that a bit and here is an implementation of map that is incremental:

    open System.Collections.Specialized
    open System.Collections.ObjectModel
    
    module ObservableCollection =
      /// Initialize observable collection
      let init n f = ObservableCollection<_>(List.init n f)
    
      /// Incremental map for observable collections
      let map f (oc:ObservableCollection<'T>) =
        // Create a resulting collection based on current elements
        let res = ObservableCollection<_>(Seq.map f oc)
        // Watch for changes in the source collection
        oc.CollectionChanged.Add(fun change ->
          printfn "%A" change.Action
          match change.Action with
          | NotifyCollectionChangedAction.Add ->
              // Apply 'f' to all new elements and add them to the result
              change.NewItems |> Seq.cast<'T> |> Seq.iteri (fun index item ->
                res.Insert(change.NewStartingIndex + index, f item))
          | NotifyCollectionChangedAction.Move ->
              // Move element in the resulting collection
              res.Move(change.OldStartingIndex, change.NewStartingIndex)
          | NotifyCollectionChangedAction.Remove ->
              // Remove element in the result
              res.RemoveAt(change.OldStartingIndex)
          | NotifyCollectionChangedAction.Replace -> 
              // Replace element with a new one (processed using 'f')
              change.NewItems |> Seq.cast<'T> |> Seq.iteri (fun index item ->
                res.[change.NewStartingIndex + index] <- f item)
          | NotifyCollectionChangedAction.Reset ->
              // Clear everything
              res.Clear()
          | _ -> failwith "Unexpected action!" )
        res
    

    Implementing map was quite easy, but I’m afraid that functions like collect and groupBy will be quite tricky. Anyway, here is a sample showing how you can use it:

    let src = ObservableCollection.init 5 (fun n -> n)
    let res = ObservableCollection.map (fun x -> printfn "processing %d" x; x * 10) src
    
    src.Move(0, 1)
    src.Remove(0)
    src.Clear()
    src.Add(5)
    src.Insert(0, 3)
    src.[0] <- 1
    
    // Compare the original and the result
    printfn "%A" (Seq.zip src res |> List.ofSeq)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a map simmilar to this: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/examples/advanced_example.html One of the
I would like to implement a switch button, android.widget.Switch (available from API v.14). <Switch
I would like to implement a fast search on an ArrayList of objects. These
I would like to implement a distinct thread for each route in apache camel.I
I would like to implement a very simple way to store a variable containing
I would like to implement a function with R that removes repeated characters in
I would like to implement a simple queueing service specific to a project. Where
I would like to implement a simple AR desktop application. This application should first
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
We would like to implement a web form that automatically saves content at regular

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.