A small clone of ramda
Project description
python_ramda
This is a repo try to copy https://github.com/ramda/ramda in python.
install
For whom wants to use this package.
> pip install python_ramda
> pip install python_ramda -U # get the latest
Usage
>>> from ramda import curry
>>> def sum(a, b, c): return a + b + c
>>> curry(sum)(1)(2, 3)
6
>>> import ramda as R # similar to ramda syntax
>>> def sum(a, b, c): return a + b + c
>>> R.curry(sum)(1)(2, 3)
6
Doc
Because the usage of python_ramda
is almostly same to ramda
,
so we don't create any extra doc.
If you feel any behaviour is different from what is should be in ramda
,
please check below CheckList
for more details.
Contribute
For whom wants to contribute to this repo.
# see: https://pre-commit.com/ for more details
$ pre-commit install # please install hooks first
Checkout new branch from main
branch directly and create PR.
CheckList
Functions supported now.
- __
- add
# different from ramda, ramda treat null as 0
>>> R.add(None, None) # float('nan)
- addIndex
- adjust
- all
- Transducer part is not fully tested.
- allPass
- always
- And (
and
is a keyword in python) - andThen
- any
- anyPass
- ap
- aperture
- append
- apply
- applySpec
- applyTo
- ascend
- assoc
- assocPath
- binary
- bind
- both
- call
- chain
- clamp
- clone
we are simply using python copy
module
So with no specific reason, we suggest you to use python origin copy
module as your first choice.
class Obj:
def __init__(self, x):
self.value = x
obj = Obj(42)
clone = R.clone(obj)
obj == clone # False, obj and clone have different references
isinstance(clone, Obj) # True
class Obj:
def __init__(self, x):
self.value = x
def __eq__(self, other):
return self.value == other.value
obj = Obj(42)
clone = R.clone(obj)
obj == clone # True, if Obj override __eq__ function
isinstance(clone, Obj) # True
- collectBy
- comparator
- complement
- compose
- composeWith
- concat
- cond
- construct
- constructN
- converge
- count
- countBy
- curry
- curryN
- dec
- defaultTo
- descend
- difference
- differenceWith
- dissoc
- dissocPath
- divide
- drop
- dropLast
- dropLastWhile
- dropRepeats
- dropRepeatsWith
- dropWhile
- either
- empty
- endsWith
- eqBy
- eqProps
# works for both dict and object
class Obj:
def __init__(self, v):
self.v = v
obj1 = Obj(1)
obj2 = Obj(1)
R.eqProps('v', obj1, obj2) # True
R.eqProps('v', {'v': 1}, {'v': 1}) # True
- equals
- evolve
- F
- filter
- find
- findIndex
- findLast
- findLastIndex
- flatten
- flip
- forEach
- forEachObjIndexed
- fromPairs
- groupBy
- groupWith
- gt
- gte
- has
- hasIn
- hasPath
- head
- identical
- identity
- ifElse
- inc
- includes
- indexBy
- indexOf
- init
- innerJoin
- insert
- insertAll
- intersection
- intersperse
- into
- invert
- invertObj
- invoker
- is
- isEmpty
- isNil
- join
- juxt
- keys
# When using R.keys(obj) and obj is a class instance, we use obj.__dict__ as keys.
class A:
c = 'not included'
def __init__(self):
self.a = 1
self.b = 2
a = A()
R.keys(a) # ['a', 'b']
- keysIn
- last
- lastIndexOf
- length
- lens
- lensIndex
- lensPath
- lensProp
- lift
- liftN
- lt
- lte
- Map (
map
is a keyword in python) - mapAccum
- mapAccumRight
- mapObjIndexed
- match
- mathMod
- max
- maxBy
- mean
- median
- memoizeWith
- mergeAll
- mergeDeepLeft
- mergeDeepRight
- mergeDeepWith
- mergeDeepWithKey
- mergeLeft
- mergeRight
- mergeWith
- mergeWithKey
- min
- minBy
- modify
- modifyPath
- modulo
- move
- multiply
- nAry
- negate
- none
- not
- nth
- nthArg
- o
- objOf
- of
- omit
- on
- once
- or
- otherwise
- over
- pair
- partial
- partialObject
- partialRight
- partition
- path
- pathEq
- pathOr
- paths
- pathSatisfies
- pick
- pickAll
- pickBy
- pipe
- pipeWith
- pluck
- prepend
- product
- project
- promap
- prop
- propEq
- propIs
- propOr
- props
- propSatisfies
- range
- reduce
- reduceBy
- reduced
- reduceRight
- reduceWhile
- reject
- remove
- repeat
- replace
- reverse
- scan
- sequence
- set
- slice
- sort
- sortBy
- sortWith
- split
- splitAt
- splitEvery
- splitWhen
- splitWhenever
- startsWith
- subtract
- sum
- symmetricDifference
- symmetricDifferenceWith
- T
- tail
- take
- takeLast
- takeLastWhile
- takeWhile
- tap
- test
- thunkify
- times
- toLower
- toPairs
- toPairsIn
- toString
- toUpper
- transduce
- transpose
- traverse
- trim
- tryCatch
- type
- unapply
- unary
- uncurryN
- unfold
- union
- unionWith
- uniq
- uniqBy
- uniqWith
- unless
- unnest
- until
- unwind
- update
- useWith
- values
- valuesIn
- view
- when
- where
- whereAny
- whereEq
- without
- xor
- xprod
- zip
- zipObj
- zipWith
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_ramda-0.0.10.tar.gz
.
File metadata
- Download URL: python_ramda-0.0.10.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6de4fc99c6e70105ae830d9e4b031211f938e8ca8643d824b2b55c216482004b
|
|
MD5 |
e5658e1897b014c4dabfac64886534e7
|
|
BLAKE2b-256 |
9d413df8388e377eb6aeef641c2a56bc46b54755b57386aed3f99bd0cd9ae83a
|
File details
Details for the file python_ramda-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: python_ramda-0.0.10-py3-none-any.whl
- Upload date:
- Size: 65.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b99403f9004b891c5ff2da89024ea367738cf6fa2429bd6bf873479b6fc7e741
|
|
MD5 |
a33fbd5efa86dfc92f024c8ff3b7fa11
|
|
BLAKE2b-256 |
6062ab3cfce8fa0168dc24378508985a8f803c8295fa6461580099a54dbf56cf
|