Skip to content

Commit 95e85ae

Browse files
committed
ifttt func implemented
version bump 0.0.6
1 parent 357264d commit 95e85ae

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

maz/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,17 @@ def __call__(self, objects: typing.Iterable[typing.Any]) -> typing.Iterable[typi
349349
),
350350
key=operator.itemgetter(0),
351351
)
352-
)
352+
)
353+
354+
class ifttt:
355+
356+
def __init__(self, fnif, fnthen, fnelse):
357+
self.fnif = fnif
358+
self.fnthen = fnthen
359+
self.fnelse = fnelse
360+
361+
def __call__(self, obj: typing.Any) -> typing.Any:
362+
if self.fnif(obj):
363+
return self.fnthen(obj)
364+
else:
365+
return self.fnelse(obj)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = maz
3-
version = 0.0.5
3+
version = 0.0.6
44
author = ourstudio
55
author_email = rikard@ourstudio.se
66
description = Functional programming tools.

tests/test_maz.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,41 @@ def __eq__(self, o):
126126
Var("d", 5),
127127
Var("e", 6),
128128
]
129+
assert actual == expected
130+
131+
def test_ifttt_function():
132+
133+
class Var:
134+
def __init__(self, id: str, n: int):
135+
self.id = id
136+
self.n = n
137+
138+
def __eq__(self, o):
139+
return (self.id == o.id) and (self.n == o.n)
140+
141+
items = [
142+
Var("a", 1),
143+
Var("b", 2),
144+
Var("c", 3),
145+
Var("d", 4),
146+
Var("e", 5),
147+
]
148+
149+
actual = list(
150+
map(
151+
maz.ifttt(
152+
lambda x: x.n > 2,
153+
lambda x: Var(x.id, x.n+1),
154+
lambda x: Var(x.id, x.n-1)
155+
),
156+
items
157+
)
158+
)
159+
expected = [
160+
Var("a", 0),
161+
Var("b", 1),
162+
Var("c", 4),
163+
Var("d", 5),
164+
Var("e", 6),
165+
]
129166
assert actual == expected

0 commit comments

Comments
 (0)