Skip to content

Commit

Permalink
Create normalize_topic_list function
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Jul 30, 2018
1 parent c7807f7 commit f69f30e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web3/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,21 @@ def get_event_data(event_abi, log_entry):
}

return AttributeDict.recursive(event_data)


@to_tuple
def pop_singlets(seq):
yield from (i[0] if is_list_like(i) and len(i) == 1 else i for i in seq)


@curry
def remove_trailing_from_seq(seq, remove_value=None):
index = len(seq)
while index > 0 and seq[index - 1] == remove_value:
index -= 1
return seq[:index]


normalize_topic_list = compose(
remove_trailing_from_seq(remove_value=None),
pop_singlets,)

0 comments on commit f69f30e

Please sign in to comment.