ds300 / derivablejs

Functional Reactive State for JavaScript and TypeScript
Apache License 2.0
515 stars 23 forks source link

Add map, mMap combinators #90

Closed TrySound closed 6 years ago

TrySound commented 6 years ago

Proposed in https://github.com/ds300/derivablejs/pull/89 map and mMap methods. Not overloaded versions are 25% faster as you can find in added benchmarks

"mapper": {
  "derive": {
    "hz": 7.157623587567227,
    "rme": 6.148182799800633,
    "samples": 22
  },
  "map": {
    "hz": 9.601906213218516,
    "rme": 6.922336536128435,
    "samples": 28
  }
}

/cc @ds300 @andreypopp

ds300 commented 6 years ago

Nice work on the perf! As mentioned in #89 I think I'd prefer if these remained being called derive and mDerive, since map is normally used for transforming collections or streams, but that's only a soft preference. If you prefer map and mMap a lot more, then I'm happy for you to make that change too.

TrySound commented 6 years ago

Derivable with derive method is functor in terms of fp, so it won't confuse and conflict with different types (types + namespace). Also derive method will conflict with lightweight derive function, since they'll have different functionality.

ds300 commented 6 years ago

Ok, go for it! :+1: