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 @@ -514,7 +514,7 @@ R.values({'a': 1, 'b': 2}) # [1, 2]
- [ ] whereEq
- [ ] without
- [ ] xor
- [ ] xprod
- [x] xprod
- [ ] zip
- [ ] zipObj
- [ ] zipWith
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@
from .uniqWith import uniqWith
from .useWith import useWith
from .values import values
from .xprod import xprod
18 changes: 18 additions & 0 deletions ramda/xprod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .private._curry2 import _curry2


def inner_xprod(a, b):
idx = 0
ilen = len(a)
jlen = len(b)
result = []
while idx < ilen:
j = 0
while j < jlen:
result.append([a[idx], b[j]])
j += 1
idx += 1
return result


xprod = _curry2(inner_xprod)
21 changes: 21 additions & 0 deletions test/test_xprod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import unittest

import ramda as R

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


class TestXProd(unittest.TestCase):
def test_returns_an_empty_list_if_either_input_list_is_empty(self):
self.assertEqual([], R.xprod([], [1, 2, 3]))
self.assertEqual([], R.xprod([1, 2, 3], []))

def test_creates_the_collection_of_all_cross_product_pairs_of_its_parameters(self):
self.assertEqual([[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']], R.xprod([1, 2], ['a', 'b', 'c']))


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