def evaluate(self, calculator, divide=False): scss_pairs = [] for key, value in self.pairs: scss_pairs.append(( key.evaluate(calculator), value.evaluate(calculator), )) return Map(scss_pairs)
def map_merge(*maps): key_order = [] index = {} for map in maps: for key, value in map.to_pairs(): if key not in index: key_order.append(key) index[key] = value pairs = [(key, index[key]) for key in key_order] return Map(pairs, index=index)
def map_merge_deep(*maps): pairs = [] keys = set() for map in maps: for key, value in map.to_pairs(): keys.add(key) for key in keys: values = [map.to_dict().get(key, None) for map in maps] values = [v for v in values if v is not None] if all(isinstance(v, Map) for v in values): pairs.append((key, map_merge_deep(*values))) else: pairs.append((key, values[-1])) return Map(pairs)