Skip to content
/ jboc Public

No dependencies, no paradigm - Just a Bunch Of Code

License

Notifications You must be signed in to change notification settings

maxme1/jboc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

No dependencies, no paradigm - Just a Bunch Of Code

A small collection of some useful code that didn't fit into any package that I know of.

Examples

Turn a generator function into a function that returns a list:

from jboc import collect


@collect
def odd_numbers(n):
    for i in range(n):
        yield 2 * i + 1


# not a generator anymore
odd_numbers(3) == [1, 3, 5] 

Same as before, but gather the values into a different container, e.g. a dict:

from jboc import composed


@composed(dict)
def vals_to_squares(values):
    for v in values:
        yield v, v ** 2


# the pairs are gathered in a dict
vals_to_squares([3, 2, 8]) == {3: 9, 2: 4, 8: 64}

Install

pip install jboc

About

No dependencies, no paradigm - Just a Bunch Of Code

Topics

Resources

License

Stars

Watchers

Forks

Languages