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 @@ -197,7 +197,7 @@ R.equals(float('nan'), float('nan')) # True
- [x] 0.1.2 flip
- [x] 0.1.4 forEach
- [ ] forEachObjIndexed
- [ ] fromPairs
- [x] fromPairs
- [x] 0.1.2 groupBy
- [ ] groupWith
- [x] 0.1.2 gt
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .flatten import flatten
from .flip import flip
from .forEach import forEach
from .fromPairs import fromPairs
from .groupBy import groupBy
from .gt import gt
from .gte import gte
Expand Down
13 changes: 13 additions & 0 deletions ramda/fromPairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .private._curry1 import _curry1


def inner_fromPairs(pairs):
result = {}
idx = 0
while idx < len(pairs):
result[pairs[idx][0]] = pairs[idx][1]
idx += 1
return result


fromPairs = _curry1(inner_fromPairs)
19 changes: 19 additions & 0 deletions test/test_fromPair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import unittest

import ramda as R

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


class TestFromPair(unittest.TestCase):
def test_combines_an_array_of_two_element_arrays_into_a_dict(self):
self.assertEqual({'a': 1, 'b': 2, 'c': 3}, R.fromPairs([['a', 1], ['b', 2], ['c', 3]]))

def test_gives_later_entries_precedence_over_earlier_ones(self):
self.assertEqual({'x': 2}, R.fromPairs([['x', 1], ['x', 2]]))

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