Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ R.length(ObjWithoutLength()) # float('nan')
- [ ] lensIndex
- [ ] lensPath
- [ ] lensProp
- [ ] lift
- [x] lift
- [x] liftN
- [x] 0.1.2 lt
- [x] 0.1.2 lte
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from .last import last
from .lastIndexOf import lastIndexOf
from .length import length
from .lift import lift
from .liftN import liftN
from .lt import lt
from .lte import lte
Expand Down
5 changes: 5 additions & 0 deletions ramda/lift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .liftN import liftN
from .private._curry1 import _curry1
from .private._inspect import funcArgsLength

lift = _curry1(lambda fn: liftN(funcArgsLength(fn), fn))
42 changes: 42 additions & 0 deletions test/test_lift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

import unittest

import ramda as R
from ramda.private._isFunction import _isFunction

from .helpers.Maybe import Just

"""
https://github.com/ramda/ramda/blob/master/test/lift.js
"""

add3 = R.curry(lambda a, b, c: a + b + c)
add4 = R.curry(lambda a, b, c, d: a + b + c + d)
add5 = R.curry(lambda a, b, c, d, e: a + b + c + d + e)
complement = R.lift(R.Not)
madd3 = R.lift(add3)
madd4 = R.lift(add4)
madd5 = R.lift(add5)


class TestLift(unittest.TestCase):
def test_returns_a_function_if_called_with_just_a_function(self):
self.assertEqual(True, _isFunction(R.lift(R.add)))

def test_produces_a_cross_product_of_array_values(self):
self.assertEqual([3, 4, 5, 4, 5, 6, 4, 5, 6, 5, 6, 7, 5, 6, 7, 6, 7, 8], madd3([1, 2, 3], [1, 2], [1, 2, 3]))
self.assertEqual([6], madd3([1], [2], [3]))
self.assertEqual([9, 10, 10, 11, 10, 11, 11, 12], madd3([1, 2], [3, 4], [5, 6]))

def test_can_lift_functions_of_any_arity(self):
self.assertEqual(False, complement(R.isNil)(None))
self.assertEqual([6, 15], madd3([1, 10], [2], [3]))
self.assertEqual([46, 55], madd4([1, 10], [2], [3], [40]))
self.assertEqual([546, 1046, 555, 1055], madd5([1, 10], [2], [3], [40], [500, 1000]))

def test_works_with_other_functors_such_as_maybe(self):
addM = R.lift(R.add)
self.assertEqual(True, R.equals(Just(8), addM(Just(3), Just(5))))

if __name__ == '__main__':
unittest.main()