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
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Python modulo on negative numbers has different behavior than JS.
```

```js
5 % -3 // 2
5 % -3; // 2
```

- [ ] move
Expand Down Expand Up @@ -600,6 +600,8 @@ class A:
def __init__(self, v2):
self.v2 = v2

R.toPairs(A(1)) # [['v2', 1]]

class B(A):
v3 = 'not included'
def __init__(self, v2, v4):
Expand All @@ -610,7 +612,27 @@ b = B('v2', 'v4')
R.toPairs(b) # [['v2', 'v2'], ['v4', 'v4']]
```

- [ ] toPairsIn
- [x] toPairsIn

```python
R.toPairsIn({'a': 1, 'b': 2}) # [['a', 1], ['b', 2]]

class A:
v1 = 'included'
def __init__(self, v2):
self.v2 = v2

R.toPairsIn(A('v2')) # [['v1', 'included'], ['v2', 'v2']]

class B(A):
v3 = 'included too'
def __init__(self, v2, v4):
super().__init__(v2) # this is required
self.v4 = v4

R.toPairsIn(B('v2', 'v4')) # [['v3', 'included too'], ['v1', 'included'], ['v2', 'v2'], ['v4', 'v4']]
```

- [x] 0.1.2 toString

Partially supported
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
from .tap import tap
from .times import times
from .toPairs import toPairs
from .toPairsIn import toPairsIn
from .toString import toString
from .unary import unary
from .union import union
Expand Down
13 changes: 13 additions & 0 deletions ramda/toPairsIn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .keysIn import keysIn
from .private._curry1 import _curry1
from .private._helper import getAttribute


def inner_toPairsIn(obj):
pairs = []
for key in keysIn(obj):
pairs.append([key, getAttribute(obj, key)])
return pairs


toPairsIn = _curry1(inner_toPairsIn)
43 changes: 43 additions & 0 deletions test/test_toPairsIn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import unittest

import ramda as R

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


class TestToPairsIn(unittest.TestCase):
def test_converts_a_dict_into_an_array_of_two_element_key_value_arrays(self):
self.assertEqual([['a', 1], ['b', 2], ['c', 3]], R.toPairsIn({'a': 1, 'b': 2, 'c': 3}))

def test_converts_an_object_into_an_array_of_two_element_key_value_arrays(self):
class A:
a = 'you can see me'

def __init__(self, b):
self.b = b
a = A('b')
self.assertEqual([['a', 'you can see me'], ['b', 'b']], R.toPairsIn(a))

class B(A):
c = 'you can see me too'

def __init__(self, b, d):
super().__init__(b)
self.d = d
b = B('b', 'd')
self.assertEqual([['c', 'you can see me too'], ['a', 'you can see me'], ['b', 'b'], ['d', 'd']], R.toPairsIn(b))

class C(A):
c = 'you can see me too'

def __init__(self, d):
self.d = d
c = C('d')
self.assertEqual([['c', 'you can see me too'], ['a', 'you can see me'], ['d', 'd']], R.toPairsIn(c))


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