Skip to content

Commit

Permalink
Different interface for python 3
Browse files Browse the repository at this point in the history
- iterator version of utils by default,
- no i-prefixed functions for iterator versions,
- l-prefixed functions for list versions,
  including lmap(), lfilter() and lzip()
  • Loading branch information
Suor committed Dec 27, 2013
1 parent fb4702e commit eb62cb2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- added experimental python 3 support
- published idistinct(), isplit(), isplit_at(), isplit_by()

0.8
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ A collection of fancy functional tools focused on practicality.
Inspired by clojure, underscore and my own abstractions. Keep reading to get an overview
or `read the docs <http://funcy.readthedocs.org/>`_.

Works with Python 2.7, 3.3 (experimental) and pypy.


Installation
-------------
Expand Down
20 changes: 6 additions & 14 deletions funcy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
from .primitives import *
from .calc import *
from .colls import *
from .decorators import *
from .funcolls import *
from .funcs import *
from .seqs import *
from .types import *
from .strings import *
from .flow import *
from .objects import *
from .namespaces import namespace
from .debug import *
from .primitives import *
import sys

if sys.version_info[0] == 2:
from .py2 import *
else:
from .py3 import *
14 changes: 14 additions & 0 deletions funcy/py2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .primitives import *
from .calc import *
from .colls import *
from .decorators import *
from .funcolls import *
from .funcs import *
from .seqs import *
from .types import *
from .strings import *
from .flow import *
from .objects import *
from .namespaces import namespace
from .debug import *
from .primitives import *
41 changes: 41 additions & 0 deletions funcy/py3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Rewrite function names to represent Python 3 iterator-by-default interface.
List versions go with l prefix.
"""
from .py2 import *

# colls
del iteritems
zip_values = izip_values; del izip_values
zip_dicts = izip_dicts; del izip_dicts

# seqs
lmap, map = map, imap; del imap
lfilter, filter = filter, ifilter; del ifilter
lremove, remove = remove, iremove; del iremove
lkeep, keep = keep, ikeep; del ikeep
lwithout, without = without, iwithout; del iwithout

lconcat, concat = concat, iconcat; del iconcat
lcat, cat = cat, icat; del icat
lflatten, flatten = flatten, iflatten; del iflatten
lmapcat, mapcat = mapcat, imapcat; del imapcat

ldistinct, distinct = distinct, idistinct; del idistinct
lsplit, split = split, isplit; del isplit
lsplit_at, split_at = split_at, isplit_at; del isplit_at
lsplit_by, split_by = split_by, isplit_by; del isplit_by
lpartition, partition = partition, ipartition; del ipartition
lchunks, chunks = chunks, ichunks; del ichunks
lpartition_by, partition_by = partition_by, ipartition_by; del ipartition_by

lreductions, reductions = reductions, ireductions; del ireductions
lsums, sums = sums, isums; del isums

# py2 re-exports izip, so py3 exports lzip
zip = izip; del izip
def lzip(*seqs):
return list(zip(*seqs))

# funcs
ljuxt, juxt = juxt, ijuxt; del ijuxt

0 comments on commit eb62cb2

Please sign in to comment.