Skip to main content

Infix data structures for Python

Project description


See blog post, Introducing infixpy: 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.

Stephen's Direct from Scala example

Scala version

val a = ((1 to 50)
  .map(_ * 4)
  .filter( _ <= 170)
  .filter(_.toString.length == 2)
  .filter (_ % 20 == 0)
  .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)
     .map(lambda x: 'Result[%d]=%s' %(x[0],x[1]))
     .mkstring(' .. '))
  # Result[0]=20  .. Result[1]=40  .. Result[2]=60  .. Result[3]=80

Original Example

from infixpy import Seq

 .map(lambda x: x+3)
 .filter(lambda x: x%2==0)
 .groupby(lambda x: x%3)




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 Distribution

infixpy-0.4.0.tar.gz (9.0 kB view hashes)

Uploaded Source

Supported by

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