Infix data structures for Python
Project description
infixpy
This is adapted from Matt Hagy's scalaps: See blog post, Introducing scalaps: Scala-inspired data structures for Python to learn about using this library.
A functional, object-oriented approach for working with sequences and collections. Also similar to Spark RDDs and Java Streams. Hope you find they simplify your code by providing a plethora of common algorithms for working with sequences and collections.
Direct from Scala example
Scala version
val a = ((1 to 50)
.map(_ * 4)
.filter( _ <= 170)
.filter(_.toString.length == 2)
.filter (_ % 20 == 0)
.zipWithIndex
.map{ case(x,n) => s"Result[$n]=$x"}
.mkString(" .. "))
a: String = Result[0]=20 .. Result[1]=40 .. Result[2]=60 .. Result[3]=80
Version using the infixpy library with python
from infixpy import *
a = (Seq(range(1,51))
.map(lambda x: x * 4)
.filter(lambda x: x <= 170)
.filter(lambda x: len(str(x)) == 2)
.filter( lambda x: x % 20 ==0)
.enumerate()
.map(lambda x: 'Result[%d]=%s' %(x[0],x[1]))
.mkstring(' .. '))
print(a)
# Result[0]=20 .. Result[1]=40 .. Result[2]=60 .. Result[3]=80
Original Example
from infixpy import Seq
(Seq(range(10))
.map(lambda x: x+3)
.filter(lambda x: x%2==0)
.group_by(lambda x: x%3)
.items()
.for_each(print))
Output
(1, SList([4, 10]))
(0, SList([6, 12]))
(2, SList([8]))
One-liners from the command line!
python -c "from infixpy import * ; x = Seq([(1,'a'),(2,'b'),(1,'bbcc,sfs'),(2,'c')]).groupby(lambda _: _[0]).mapvalues(lambda v: list(v)[0:2]) ; print(x)"
{1: [(1, 'a'), (1, 'bbcc,sfs')], 2: [(2, 'b'), (2, 'c')]}
Examples
See examples/ directory for additional examples of using infixpy.
Also see example usages in career_village_entities.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infixpy-0.0.6-py3.7.egg.
File metadata
- Download URL: infixpy-0.0.6-py3.7.egg
- Upload date:
- Size: 100.4 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08772001562cf5811c6535962282b63a100328180614a0d11f72f81dad5c9090
|
|
| MD5 |
f44028288e382f04b22c404cab0a6efe
|
|
| BLAKE2b-256 |
54698ae9966a0e0ef8d66662cae1975f753725f82d43bcbb88623f9ddb1c522b
|