@@ -53,24 +53,14 @@ private Function sortedMapFunction(final Supplier<SortedMap<Value, Value>> mapSu
5353 case 0 : // treeMap()
5454 map = mapSupplier .get ();
5555 break ;
56- case 1 : // treeMap(map) || treeMap(comparator)
57- if (args [0 ].type () == Types .MAP ) {
58- map = mapSupplier .get ();
59- map .putAll (((MapValue ) args [0 ]).getMap ());
60- } else if (args [0 ].type () == Types .FUNCTION ) {
61- final Function comparator = ValueUtils .consumeFunction (args [0 ], 0 );
62- map = comparatorToMapFunction .apply ((o1 , o2 ) -> comparator .execute (o1 , o2 ).asInt ());
63- } else {
64- throw new TypeException ("Map or comparator function expected in first argument" );
65- }
56+ case 1 : // treeMap(map)
57+ map = mapSupplier .get ();
58+ map .putAll (ValueUtils .consumeMap (args [0 ], 0 ).getMap ());
6659 break ;
6760 case 2 : // treeMap(map, comparator)
68- if (args [0 ].type () != Types .MAP ) {
69- throw new TypeException ("Map expected in first argument" );
70- }
7161 final Function comparator = ValueUtils .consumeFunction (args [1 ], 1 );
7262 map = comparatorToMapFunction .apply ((o1 , o2 ) -> comparator .execute (o1 , o2 ).asInt ());
73- map .putAll ((( MapValue ) args [0 ]).getMap ());
63+ map .putAll (ValueUtils . consumeMap ( args [0 ], 0 ).getMap ());
7464 break ;
7565 default :
7666 throw new IllegalStateException ();
0 commit comments