0

I see the factory constructor factory IMap.fromPairs(FoldableOps<dynamic, Tuple2<K, V>> foldableOps, Order<K> kOrder), but how do you use FoldableOps to be able to pass an Iterable<Tuple2<X,Y>> into it?

voxoid
  • 1,164
  • 1
  • 14
  • 31
  • If there is no dartz documentation currently, then consider instead perhaps this [abstract dartz art installation](https://pub.dev/documentation/dartz/latest/). – Abion47 Feb 03 '23 at 18:00
  • 1
    I'd really skip dartz entirely and move over to fpdart, which is actively maintained, and completely documented, both individual methods and some nice overview tutorials. – Randal Schwartz Feb 03 '23 at 18:58
  • @RandalSchwartz fpdart looks really good, though it doesn't yet provide immutable collection impls. Do you know of any other better immutable collection libs? I also tried dartx, but it was missing a lot of collection functions i was used to. – voxoid Feb 03 '23 at 19:35
  • 1
    I just use "Fast Immutable Collections" package. They don't have all the higher-kinded-type functionality that fpdart gives to most types, but they work fine with most of the List and Map extensions of fpdart, as well as core uses with Option and Either and friends. – Randal Schwartz Feb 03 '23 at 20:00

1 Answers1

0

After consulting the aforementioned art installation (you know, in lieu of official documentation) as well as some sample code in the repo, I believe this is the way to do it:

iList<Tuple<K, T>> tuples = ...;
IMap<K, T> map = IMap.fromPairs(tuples, Order<K>);

Where what you pass for Order<K> depends on the key type in the tuples. If it's a native type like int or String, you can pass IntOrder or StringOrder. Otherwise, you will need to create an Order implementation for that type, e.g.:

class Foo extends Comparable {
  ...
}
Order<Foo> fooOrder = ComparableOrder<Foo>();
iList<Tuple<Foo, dynamic>> tuples = ...;
iMap<Foo, dynamic> map = iMap.fromPairs(tuples, fooOrder);
Abion47
  • 22,211
  • 4
  • 65
  • 88