def __add__(self, other): if isinstance(other, dict): return self.with_dic(other) if isinstance(other, list) or isinstance(other, set): from mc._list import List return self.with_dic(List(other).to_dict()) raise AssertionError("Not supported type, should be list, dict or set")
def to_list(self): from mc._list import List return List([(key, self[key]) for key in self])
def vals(self): from mc._list import List return List(self.values())
def keys(self): from mc._list import List return List([key for key in self])
def test_chaining_glues_callables(): assert_that( List([1, 2, 3]).map(chain(lambda x: x * x, str, lambda y: "_" + y)), equal_to(List(["_1", "_4", "_9"])))
def to_list(self): from mc._list import List return List(self.value)
def test_multiplication(): assert_that(List([1, 2, 4]).reduce(multiply).get(), equal_to(8))
def test_subtraction(): assert_that(List([1, 2, 4]).fold(subtr, 100), equal_to(93))
def test_addition(): assert_that(List([1, 2, 4]).reduce(add).get(), equal_to(7))
def test_mux_multilexes_unnamed_callables(): import math assert_that( mux(sum=sum, maximum=max)(List([1, 2, 3])), equal_to(dict(sum=6, maximum=3)))
def test_mux_multilexes_unnamed_callables(): import math assert_that(mux(sum, lambda x: x[0])(List([1, 2, 3])), equal_to((6, 1)))