Skip to content

Commit 2b865c7

Browse files
authored
Add infix version of map (#28)
1 parent 77bd523 commit 2b865c7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

oslash/maybe.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ def reducer(a, b):
6666

6767
return reduce(reducer, xs, cls.empty())
6868

69+
def __rmod__(self, fn):
70+
"""Infix version of map.
71+
72+
Haskell: <$>
73+
74+
Example:
75+
>>> (lambda x: x+2) % Just(40)
76+
42
77+
78+
Returns a new Functor.
79+
"""
80+
return self.map(fn)
81+
6982

7083
class Just(Maybe[TSource]):
7184
"""A Maybe that contains a value.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'License :: OSI Approved :: MIT License',
3232
'Operating System :: OS Independent',
3333
'Programming Language :: Python :: 3.8',
34+
'Programming Language :: Python :: 3.9',
3435
'Topic :: Software Development :: Libraries :: Python Modules',
3536
],
3637
install_requires=['typing_extensions'],

0 commit comments

Comments
 (0)