Skip to content

Commit

Permalink
make changes to work with both python 3 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaszurkan-optimizely committed Nov 14, 2017
1 parent caf64a7 commit 650d04d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions optimizely/notification_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# limitations under the License.
import sys

from functools import reduce
from .helpers import enums


Expand All @@ -21,7 +22,7 @@ class NotificationCenter(object):
def __init__(self, logger):
self.notification_id = 1
self.notifications = {}
for attr, value in enums.NotificationTypes.__dict__.items():
for (attr, value) in enums.NotificationTypes.__dict__.items():
self.notifications[value] = []
self.logger = logger

Expand All @@ -39,7 +40,9 @@ def add_notification_listener(self, notification_type, notification_callback):
if notification_type not in self.notifications:
self.notifications[notification_type] = [(self.notification_id, notification_callback)]
else:
if len(filter(lambda tup: tup[1] == notification_callback, self.notifications[notification_type])) > 0:
if reduce(lambda a, b: a + 1,
filter(lambda tup: tup[1] == notification_callback, self.notifications[notification_type]),
0) > 0:
return -1
self.notifications[notification_type].append((self.notification_id, notification_callback))

Expand All @@ -60,7 +63,7 @@ def remove_notification_listener(self, notification_id):
"""

for v in self.notifications.values():
toRemove = filter(lambda tup: tup[0] == notification_id, v)
toRemove = list(filter(lambda tup: tup[0] == notification_id, v))
if len(toRemove) > 0:
v.remove(toRemove[0])
return True
Expand Down

0 comments on commit 650d04d

Please sign in to comment.