raveclassic / frp-ts

Functional reactive values-over-time
MIT License
79 stars 8 forks source link

feat: distinctUntilChanged operator #59

Open tamazlykar opened 2 years ago

tamazlykar commented 2 years ago

Hi @raveclassic. Thanks for your lib. I have a next example of usage of your library and wanna propose an operator for this. const sortedElements = property.combine(data, elements, sortElements); I have an array of some elements that should be sorted based on data. So when the data is updates i recalculate a new sortedElements, and it may have same order but different reference. So i need an ability to have a custom comparator function to omit some of the Property changes.

Looks like a distinctUntilChanged operator from rxjs can be a good fit for this, but with mandatory comparator, because frp-ts not emit when values has same reference. I make an implementation of this function as proposal for example https://github.com/raveclassic/frp-ts/pull/58. So maybe it will be helpful for other devs too. Can you take a look?

raveclassic commented 2 years ago

Let's continue the discussion here. Ok so the use case is that you want to sort a list, but the Array.prototype.sort mutates the source array, right? It seems the correct way is to slice the source before sorting.