Skip to main content

A small clone of ramda

Project description

python_ramda

This is a repo try to copy https://github.com/ramda/ramda in python.

linting: pylint

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.

$ pip install -U pylint
# 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.

  • 0.1.0 __
  • 0.1.0 add
# different from ramda
R.add(None, None) # float('nan)
R.add(date(1,2,3), date(1,2,3)) # float('nan)
  • addIndex
  • 0.1.0 adjust
  • 0.1.0 all
    • Transducer part is not fully tested.
  • allPass
  • 0.1.0 always
  • 0.1.0 And (and is a keyword in python)
  • andThen
  • 0.1.0 any
  • anyPass
  • ap
  • aperture
  • 0.1.0 append
  • apply
  • applySpec
  • applyTo
  • ascend
  • assoc
  • assocPath
  • binary
  • bind
  • both
  • call
  • chain
  • clamp
  • 0.1.0 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
  • 0.1.0 comparator
  • complement
  • 0.1.0 compose
  • composeWith
  • 0.1.0 concat
  • cond
  • construct
  • constructN
  • converge
  • count
  • 0.1.0 countBy
  • 0.1.0 curry
  • 0.1.0 curryN
  • dec
  • defaultTo
  • descend
  • 0.1.0 difference
  • 0.1.0 differenceWith
  • dissoc
  • dissocPath
  • 0.1.0 divide
  • 0.1.0 drop
  • dropLast
  • dropLastWhile
  • dropRepeats
  • dropRepeatsWith
  • dropWhile
  • either
  • 0.1.0 empty
# We don't support empty object in python
class Obj:
  def __init__(self, value):
    self.value = value
o = Obj(42)
o == R.empty(o) # True, we will return the original cloned object

What we support for now:

  1. dict()
  2. set()
  3. list()
  4. str()
  5. any instance with empty() method
  6. any instance with 'fantasy-land/empty' property
  • endsWith
  • eqBy
  • 0.1.0 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
  • 0.1.0 equals
R.equals(float('nan'), float('nan')) # True
  • evolve
  • 0.1.0 F
  • 0.1.0 filter
  • 0.1.0 find
  • findIndex
  • findLast
  • findLastIndex
  • 0.1.0 flatten
  • 0.1.0 flip
  • forEach
  • forEachObjIndexed
  • fromPairs
  • 0.1.0 groupBy
  • groupWith
  • 0.1.0 gt
  • 0.1.0 gte
  • has
  • hasIn
  • hasPath
  • 0.1.0 head
  • identical
  • 0.1.0 identity
  • ifElse
  • inc
  • includes
  • indexBy
  • 0.1.0 indexOf
  • init
  • innerJoin
  • insert
  • insertAll
  • 0.1.0 intersection
  • intersperse
  • 0.1.0 into
  • invert
  • invertObj
  • 0.1.0 invoker
  • is
  • 0.1.0 isEmpty
class Obj:
  pass
# Any custom object will be treated as non-empty
R.isEmpty(Obj()) # False
R.isEmpty(None) # False
  • isNil
  • 0.1.0 join
  • juxt
  • 0.1.0 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
  • 0.1.0 lastIndexOf
  • length
  • lens
  • lensIndex
  • lensPath
  • lensProp
  • lift
  • liftN
  • 0.1.0 lt
  • 0.1.0 lte
  • 0.1.0 map
  • mapAccum
  • mapAccumRight
  • mapObjIndexed
  • 0.1.0 match
  • mathMod
  • 0.1.0 Max (max is a keyword in python)

If R.Max(a, b) a and b are with different types, we will compare with str(a) and str(b).

R.Max('A', None) # None, 'A' < 'None'
  • maxBy
  • mean
  • median
  • memoizeWith
  • mergeAll
  • mergeDeepLeft
  • mergeDeepRight
  • mergeDeepWith
  • mergeDeepWithKey
  • mergeLeft
  • mergeRight
  • mergeWith
  • mergeWithKey
  • 0.1.0 Min (min is a keyword in python)

If R.Min(a, b) a and b are with different types, we will compare with str(a) and str(b).

R.Min('A', None) # 'A', 'A' < 'None'
  • minBy
  • modify
  • modifyPath
  • modulo
  • move
  • 0.1.0 multiply
  • nAry
  • negate
  • none
  • 0.1.0 not
  • 0.1.0 nth
  • nthArg
  • o
  • 0.1.0 objOf
  • of
  • 0.1.0 omit

we support both dict type and object type.

class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj = Obj(1, 2)
R.omit(['v1'], obj) # {'v2': 2}
R.omit(['v1', 'v3'], obj) # {'v2': 2}
  • on
  • 0.1.0 once
  • 0.1.0 or
  • otherwise
  • over
  • pair
  • partial
  • partialObject
  • partialRight
  • partition
  • 0.1.0 path
  • pathEq
  • pathOr
  • 0.1.0 paths
  • pathSatisfies
  • 0.1.0 pick
  • 0.1.0 pickAll

both pick and pickAll support both dict and object type.

class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj = Obj(1, 2)
R.pick(['v1'], obj) # {'v1': 1}
R.pickAll(['v1', 'v3'], obj) # {'v1': 1, 'v3': None}
  • pickBy
  • 0.1.0 pipe
  • pipeWith
  • 0.1.0 pluck
# works for both dict and object
class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj1 = Obj(1, 2)
obj2 = Obj(3, 4)
R.pluck('v1', [obj1, obj2]) # [1, 3]
  • 0.1.0 prepend
  • 0.1.0 product
  • 0.1.0 project
# works for both dict and object
class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj1 = Obj(1, 2)
obj2 = Obj(3, 4)
R.project(['v1'], [obj1, obj2]) # [{'v1': 1}, {'v1': 3}]
  • promap
  • 0.1.0 prop
  • 0.1.0 propEq
# works for both dict and object
class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj1 = Obj(1, 2)
R.propEq(1, 'v1', obj1) # True
R.propEq(2, 'v2', obj1) # True
R.propEq(1, 'v2', obj1) # False

R.propEq(1, 'v1', {'v1': 1}) # True
  • propIs
  • propOr
  • 0.1.0 props
  • propSatisfies
  • 0.1.0 range
  • 0.1.0 reduce
  • 0.1.0 reduceBy
  • 0.1.0 reduced
  • 0.1.0 reduceRight
  • reduceWhile
  • 0.1.0 reject
  • remove
  • repeat
  • replace
  • 0.1.0 reverse
  • scan
  • sequence
  • set
  • 0.1.0 slice
R.slice(1, 3, ['a', 'b', 'c', 'd']) # ['b', 'c']
R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd']
  • 0.1.0 sort
  • 0.1.0 sortBy
  • sortWith
  • 0.1.0 split
  • splitAt
  • splitEvery
  • splitWhen
  • splitWhenever
  • startsWith
  • 0.1.0 subtract
# different from ramda
R.subtract(None, None) # float('nan)
R.subtract(date(1,2,3), date(1,2,3)) # float('nan)
  • 0.1.0 sum
  • symmetricDifference
  • symmetricDifferenceWith
  • 0.1.0 T
  • 0.1.0 tail
  • 0.1.0 take
  • takeLast
  • takeLastWhile
  • 0.1.0 takeWhile
  • 0.1.0 tap
  • test
  • thunkify
  • times
  • toLower
  • toPairs
  • toPairsIn
  • 0.1.0 toString

Partially supported

  1. String type, supported
  2. for others, just use str(x) instead
  • toUpper
  • transduce
  • transpose
  • traverse
  • trim
  • tryCatch
  • type
  • unapply
  • unary
  • uncurryN
  • unfold
  • 0.1.0 union
  • 0.1.0 unionWith
  • 0.1.0 uniq
  • 0.1.0 uniqBy
  • 0.1.0 uniqWith
  • unless
  • unnest
  • until
  • unwind
  • update
  • 0.1.0 useWith
  • 0.1.0 values
# works for both dict and object
class Obj:
  def __init__(self, v1, v2):
    self.v1 = v1
    self.v2 = v2
obj = Obj(1, 2)
R.values(obj) # [1, 2]
R.values({'a': 1, 'b': 2}) # [1, 2]
  • valuesIn
  • view
  • when
  • where
  • whereAny
  • whereEq
  • without
  • xor
  • 0.1.0 xprod
  • 0.1.0 zip
  • zipObj
  • 0.1.0 zipWith

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_ramda-0.1.2.tar.gz (52.3 kB view details)

Uploaded Source

Built Distribution

python_ramda-0.1.2-py3-none-any.whl (112.8 kB view details)

Uploaded Python 3

File details

Details for the file python_ramda-0.1.2.tar.gz.

File metadata

  • Download URL: python_ramda-0.1.2.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for python_ramda-0.1.2.tar.gz
Algorithm Hash digest
SHA256 84e0b0dcef01c8107c29e7dde6167a865fdeaa17d95db668de419e135c4fb2fd
MD5 07b7b688249cd55c40623e6b874f3b86
BLAKE2b-256 0ee76fe0f36e569cf1fd63cf8cb9252387abe785b6f984ce9f76c812cf1c0d45

See more details on using hashes here.

File details

Details for the file python_ramda-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: python_ramda-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 112.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for python_ramda-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 299003704e167bbe1ca5bff9faad6856d1b613e95325b3b2bc2500be3e9d5e21
MD5 4fe2b1feb3b1b6da66d1e47571f16368
BLAKE2b-256 223fa8151a5d90f8c33cc7450d01f4e1040fa93c09239211a465dc47ad4a387b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page