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
4 changes: 2 additions & 2 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2

# Sets up python3
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v2

# Sets up python3
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/upload-to-pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
# This workflow contains a single job called "upload"
upload:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Sets up python
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: 3.x

Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
from .toString import toString
from .toUpper import toUpper
from .trim import trim
from .unapply import unapply
from .unary import unary
from .union import union
from .unionWith import unionWith
Expand Down
2 changes: 1 addition & 1 deletion ramda/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

def compose(*arguments):
if len(arguments) == 0:
raise Exception('compose requires at least one argument')
raise ValueError('compose requires at least one argument')
return pipe(*reverse(arguments))
6 changes: 3 additions & 3 deletions ramda/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def inner_concat(a, b):
if _isArray(a):
if _isArray(b):
return a + b
raise Exception(f"{toString(b)} is not an array")
raise ValueError(f"{toString(b)} is not an array")
if _isString(a):
if _isString(b):
return a + b
raise Exception(f"{toString(b)} is not a string")
raise ValueError(f"{toString(b)} is not a string")
if a is not None and _isFunction(getAttribute(a, 'fantasy-land/concat')):
return a.get('fantasy-land/concat')(b)
if a is not None and _isFunction(a.concat):
return a.concat(b)
raise Exception(f'{a} does not have a method named "concat" or "fantasy-land/concat"')
raise ValueError(f'{a} does not have a method named "concat" or "fantasy-land/concat"')


concat = _curry2(inner_concat)
2 changes: 1 addition & 1 deletion ramda/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def inner_reduce(acc, key):
return acc

if functor is None:
raise Exception('Can not work with None')
raise ValueError('Can not work with None')
if _isFunction(functor):
return curryN(funcArgsLength(functor), lambda *arguments: fn(functor(*arguments)))
if _isArrayLike(functor):
Expand Down
2 changes: 1 addition & 1 deletion ramda/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def pipe(*arguments):
if len(arguments) == 0:
raise Exception('pipe requires at least one argument')
raise ValueError('pipe requires at least one argument')
return _arity(
funcArgsLength(arguments[0]),
reduce(_pipe, arguments[0], tail(list(arguments)))
Expand Down
2 changes: 1 addition & 1 deletion ramda/private/_arity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def f10(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, a6=__, a7=__, a8=__, a9=__, *_
m = {0: f0, 1: f1, 2: f2, 3: f3, 4: f4, 5: f5, 6: f6, 7: f7, 8: f8, 9: f9, 10: f10}
if n in m:
return m[n]
raise Exception('First argument to _arity must be a non-negative integer no greater than ten')
raise ValueError('First argument to _arity must be a non-negative integer no greater than ten')
2 changes: 1 addition & 1 deletion ramda/private/_assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def _assoc(prop, val, obj):
# We have 2 cases, dict or object
if isinstance(obj, dict):
return {**obj, prop: val}
raise Exception('We only support dict or array for assoc')
raise ValueError('We only support dict or array for assoc')
2 changes: 1 addition & 1 deletion ramda/private/_createReduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def _reduce(xf, acc, arr):
return iterableReduce(xf, acc, arr)
if _isFunction(getattr(arr, 'reduce', None)):
return methodReduce(xf, acc, arr, 'reduce')
raise Exception('reduce: list must be array or iterable')
raise ValueError('reduce: list must be array or iterable')
return _reduce
2 changes: 1 addition & 1 deletion ramda/private/_stepCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def _stepCat(obj):
return _stepCatString
if isinstance(obj, dict):
return _stepCatDict
raise Exception(f'Cannot create transformer for {obj}')
raise ValueError(f'Cannot create transformer for {obj}')
2 changes: 1 addition & 1 deletion ramda/private/_xwrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def transducer_init():
raise Exception('init not implemented on XWrap')
raise ValueError('init not implemented on XWrap')


def _xwrap(fn):
Expand Down
10 changes: 10 additions & 0 deletions ramda/unapply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .private._curry1 import _curry1


def _unapply(func):
def wrapper(*args):
return func(list(args))
return wrapper


unapply = _curry1(_unapply)
40 changes: 40 additions & 0 deletions test/test_unapply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import unittest

import ramda as R
from ramda.private._inspect import funcArgsLength

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


class TestLt(unittest.TestCase):
def test_returns_a_function_which_is_always_passed_one_argument(self):
fn = R.unapply(lambda *args: len(args))

self.assertEqual(1, fn())
self.assertEqual(1, fn('x'))
self.assertEqual(1, fn('x', 'y'))
self.assertEqual(1, fn('x', 'y', 'z'))

def test_forwards_arguments_to_decorated_function_as_an_array(self):
fn = R.unapply(lambda xs: str(xs))

self.assertEqual('[]', fn())
self.assertEqual('[2]', fn(2))
self.assertEqual('[2, 4]', fn(2, 4))
self.assertEqual('[2, 4, 6]', fn(2, 4, 6))

def test_returns_a_function_with_length_0(self):
fn = R.unapply(R.identity)
self.assertEqual(0, funcArgsLength(fn))

def test_is_the_inverse_of_R_apply(self):
f = R.Max
g = R.unapply(R.apply(f))
self.assertEqual(f(1, 2, 3), g(1, 2, 3))


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