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
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ Functions supported now.
- [x] add

```python
# different from ramda, ramda treat null as 0
>>> R.add(None, None) # float('nan)
# different from ramda
R.add(None, None) # float('nan)
R.add(date(1,2,3), date(1,2,3)) # float('nan)
```

- [ ] addIndex
Expand Down Expand Up @@ -430,13 +431,20 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd']
- [x] sort
- [x] sortBy
- [ ] sortWith
- [ ] split
- [x] split
- [ ] splitAt
- [ ] splitEvery
- [ ] splitWhen
- [ ] splitWhenever
- [ ] startsWith
- [ ] subtract
- [x] subtract

```python
# different from ramda
R.subtract(None, None) # float('nan)
R.subtract(date(1,2,3), date(1,2,3)) # float('nan)
```

- [x] sum
- [ ] symmetricDifference
- [ ] symmetricDifferenceWith
Expand All @@ -457,8 +465,8 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd']

Partially supported

- String type, supported
- for others, just use str(x) instead
1. String type, supported
1. for others, just use str(x) instead

- [ ] toUpper
- [ ] transduce
Expand Down
2 changes: 2 additions & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
from .slice import slice
from .sort import sort
from .sortBy import sortBy
from .split import split
from .subtract import subtract
from .sum import sum
from .T import T
from .tail import tail
Expand Down
3 changes: 3 additions & 0 deletions ramda/split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .invoker import invoker

split = invoker(1, 'split')
4 changes: 4 additions & 0 deletions ramda/subtract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .private._curry2 import _curry2
from .private._helper import toNumber

subtract = _curry2(lambda a, b: toNumber(a) - toNumber(b))
6 changes: 4 additions & 2 deletions test/test_add.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import unittest
from datetime import date
from math import isnan

import ramda as R

Expand All @@ -16,7 +17,8 @@ def test_coerces_its_arguments_to_numbers(self):
self.assertEqual(3, R.add('1', '2'))
self.assertEqual(3, R.add(1, '2'))
self.assertEqual(1, R.add(True, False))
self.assertTrue(math.isnan(R.add(None, None)))
self.assertTrue(isnan(R.add(None, None)))
self.assertTrue(isnan(R.add(date(1, 1, 1), date(2, 1, 1))))

def test_float(self):
self.assertEqual(4.2, R.add(1.1, 3.1))
Expand Down
19 changes: 19 additions & 0 deletions test/test_split.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/split.js
"""


class TestSplit(unittest.TestCase):
def test_splits_a_string_into_an_array(self):
self.assertEqual(['a', 'b', 'c', 'xyz', 'd'], R.split('.', 'a.b.c.xyz.d'))

def test_the_split_string_can_be_arbitrary(self):
self.assertEqual(['The C', ' in the H', ' s', ' on the m', ''], R.split('at', 'The Cat in the Hat sat on the mat'))

if __name__ == '__main__':
unittest.main()
26 changes: 26 additions & 0 deletions test/test_subtract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import unittest
from datetime import date
from math import isnan

import ramda as R

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


class TestSubtract(unittest.TestCase):
def test_subtracts_two_numbers(self):
self.assertEqual(15, R.subtract(22, 7))

def test_coerces_its_arguments_to_numbers(self):
self.assertEqual(-1, R.subtract('1', '2'))
self.assertEqual(-1, R.subtract(1, '2'))
self.assertEqual(1, R.subtract(True, False))
self.assertTrue(isnan(R.subtract(None, None)))
self.assertTrue(isnan(R.subtract(date(1, 1, 1), date(2, 1, 1))))


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