Replies: 1 comment 1 reply
-
There is already a discussion in #1288 about the difference between Now to your questions.
I hope that helps. Feel free to ask further questions. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to fp-ts and liking it. But I ran into a roadblock attempting to do something "simple" - fold/reduce a Map. Suppose you have a
Map<Person, Age>
and want to find out who is the oldest (assume Person is string and Age is number). This is easy to do with reducing - just loop through and keep track of the oldest person and then return it. My first problem was trying to find the method; there is no MAP.reduce. There is aMAP.getFoldableWithIndex
andMAP.toUnfoldable
. I couldn't figure out the first but was able to useMAP.toUnfoldable(ordString, ARRAY.Unfoldable))
, which generates an array of key value pairs, and then you can ARRAY.reduce on it - very inefficient to make that array just so I can reduce it. So then on hunting some more I see plans forReadonlyMap.reduce
. OK, didn't realize there was a difference between the read-only versions and the mutable versions and I gravitated to the shorter-name versions. Didn't even realize I wasn't using the latest version.The second problem is that even with the 2.11 version of
ReadonlyMap.reduce
you must provide anOrd
, which seems totally unnecessary (inefficient) for a lot of folding tasks.So, a few questions:
Readonly
versions of everything? Are the non-readonly versions legacy and deprecated?Related to the above and the unnecessary sorting, I'm trying to get a random element from a set. Notice that to do this I think I have to first convert the set to an array (inefficient), and the array must be sorted (inefficient). I wish there was a way to convert a set to an array in whatever order it happens to be in, without specifying a sort. But better would be a function to get a random element from a set. My experience is mostly with C# and F# and each time I instantiate a new array or map or set in a pipeline I cringe because what I really want is to use iterables. I've tried
iter-tools
and it mostly does what I want. I don't understand why iterables aren't supported in fp-ts, along with Map and Set and Array. I'm trying to figure out when to use fp-ts and when to use iter-tools.I see now that many of the methods in the Map, Array, and Set modules are not efficient. Looking something up in a Map using EQ requires looping through every object rather than using some internal hash table. As long as we're using the built-in javascript objects there is no efficiency to be had. Extra unnecessary sorting makes it theoretically worse. I'm starting to wonder if I should completely ignore performance and efficiency. For my app, I've got thousands of items in collections, not hundreds of thousands or millions, so perhaps the browser will zip through these calculations so fast the user would never notice. Maybe I shouldn't bother with iterables and just spin up tons of temporary arrays and maps just to get whatever answer I need. If I just stick with fp-ts at least my code will be understandable and correct.
Beta Was this translation helpful? Give feedback.
All reactions