Example #1
0
 def _create_or_append(self, coll, rel, value):
     if not (rel in coll):
         coll[rel] = value
         return coll
     if type(coll[rel]) == list:
         coll[rel] = r.flatten([coll[rel], value])
         return coll
     coll[rel] = [coll[rel], value]
     return coll
Example #2
0
    def accumulate_authors(self):
        _result = {}
        aliases = self.config.get('output', {}).get('aliases', {})
        for (_email, _alias) in aliases.items():
            _result[_email] = {'alias': _alias}

        _authors_instances = ramda.flatten(self._authors)
        for _author_instance in _authors_instances:
            _author = _author_instance.as_dict()
            _email = _author.get('email')
            _known = _result.get(_email, {})
            _result[_email] = author_merger.merge(_author, _known)
        self.authors = _result
Example #3
0
def test_flattens_all_nested_lists():
    assert flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]) == [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
    ]
Example #4
0
def test_curry_flatten_does_not_get_stuck_in_infinite_recursion_with_strings():
    assert flatten()(
        [1, 2, ["Hello", "World"], 5, [6, [7, 8, [9, [10, 11], 12]]]]) == [
            1,
            2,
            "Hello",
            "World",
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
        ]
Example #5
0
def test_curry_flatten_does_not_split_string_into_a_list_of_characters():
    assert flatten()("Hello World") == ["Hello World"]
Example #6
0
def test_curry_flatten_returns_non_iterable_as_is():
    assert flatten()(1) == [1]