def test_load_unload(self):
        Pipe.load('built_in_functions', 'itertools_pipes')

        def get_name(method):
            '''
      returns the name that the method has been added to Pipe as
      '''
            if isinstance(method, dict):
                if 'name' in method:
                    name = method['name']
                elif 'gener' in method:
                    name = method['gener'].__name__
                elif 'func' in method:
                    name = method['func'].__name__
                else:
                    raise ValueError('method name cannot be found.')

            else:
                name = method.__name__

            return name

        methods = tuple(
            get_name(method)
            for add_in in (built_in_functions, itertools_pipes)
            for collection in ('methods_to_add', 'map_methods_to_add')
            for method in getattr(add_in, collection))

        self.assertTrue(all(hasattr(Pipe, name) for name in methods))

        # check unloading
        with self.assertRaises(KeyError):
            Pipe.unload('not an add-in')

        Pipe.unload('built_in_functions', 'itertools_pipes')

        self.assertFalse(any(hasattr(Pipe, name) for name in methods))

        self.assertFalse(hasattr(Pipe, 'dict'))
Beispiel #2
0
from functional_pipes import Pipe

Pipe.load('built_in_functions', 'operator_pipes')
'''
Very simple example of a map reduce.
This apples the absolute value to each of the numbers and then reduces to the
maximum value.
'''
data = 1, -2, -3
absolute_max = Pipe(data).abs().max()

print(absolute_max)
'''
Reusable Piping
A pipe can be created without any data preloaded and be run multiple
times without being rebuilt each time. This is useful because it means you can put
the prebuilt pipe into a loop without the overhead of rebuilding it for every
iteration.

One system that this is good for is outline below:
  1.) generates data
  2.) runs the data through the pipe
  3.) makes changes to the data based on the result from the pipe
  4.) rerun the changed data through the pipe
  5.) repeat steps
The example below shows an implimentation of this system:
'''
data = (20, 2), (50, 9), (100, 7), (2, 5)

reusable_pipe = Pipe().map(
    lambda a, b: (20 * a, a * b)  # notice how the tuple is split automatically
Beispiel #3
0
 def setUpClass(self):
     Pipe.load('built_in_functions')
 def setUpClass(cls):
   Pipe.load('numpy_pipes')
Beispiel #5
0
 def setUpClass(self):
     Pipe.load('testing_tools')
Beispiel #6
0
 def setUpClass(self):
     Pipe.load('built_in_functions', 'custom_pipes', 'testing_tools')
 def setUpClass(self):
   Pipe.load('built_in_functions', 'itertools_pipes')
 def setUpClass(cls):
     Pipe.load('operator_pipes')