Exemplo n.º 1
0
 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")
Exemplo n.º 2
0
 def to_list(self):
     from mc._list import List
     return List([(key, self[key]) for key in self])
Exemplo n.º 3
0
 def vals(self):
     from mc._list import List
     return List(self.values())
Exemplo n.º 4
0
 def keys(self):
     from mc._list import List
     return List([key for key in self])
Exemplo n.º 5
0
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"])))
Exemplo n.º 6
0
 def to_list(self):
     from mc._list import List
     return List(self.value)
Exemplo n.º 7
0
def test_multiplication():
    assert_that(List([1, 2, 4]).reduce(multiply).get(), equal_to(8))
Exemplo n.º 8
0
def test_subtraction():
    assert_that(List([1, 2, 4]).fold(subtr, 100), equal_to(93))
Exemplo n.º 9
0
def test_addition():
    assert_that(List([1, 2, 4]).reduce(add).get(), equal_to(7))
Exemplo n.º 10
0
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)))
Exemplo n.º 11
0
def test_mux_multilexes_unnamed_callables():
    import math
    assert_that(mux(sum, lambda x: x[0])(List([1, 2, 3])), equal_to((6, 1)))