def _build_stack_commands(stack_data: StackData, prefix): # TODO could do check: if path of codeuri refers to something local, use this. # else use python commands: create_change_set -> wait -> execute_change_set return List( f'aws cloudformation package --template-file {stack_data.template_name} --s3-bucket "{stack_data.bucket}" --s3-prefix "{prefix}" --output-template-file outputSamTemplate.yaml', f'aws cloudformation deploy --template-file outputSamTemplate.yaml --stack-name {stack_data.stack_name} --capabilities CAPABILITY_IAM', 'rm outputSamTemplate.yaml') # use path for this?
def read_rest(file, data): # file, data = file_data[0], file_data[1] txt = file.readline().rstrip() if txt: row = float * List(*txt.split("\t")) return Just(data + [list(row)]) >> read_rest(file) return Just(data)
def moveKnight(pos: KnightPos) -> L[KnightPos]: c = pos[0] r = pos[1] possPos = List((c+2,r-1),(c+2,r+1),(c-2,r-1),(c-2,r+1),(c+1,r-2),(c+1,r+2),(c-1,r-2),(c-1,r+2)) return filter(lambda cr: cr[0] in range(1, 9) and cr[1] in range(1,9), possPos)
def testMonadComparisonExceptionWithNothing(self): self.givenMonads(List(1, 2, 3), Reader(7)) self.ensureComparisonRaisesException()
def testInequalityOfIdenticalTypes(self): self.givenMonads(List(1, 2, 3), List(4, 5, 6)) self.ensureMonadsAreNotEqual()
def testEqualityOfIdenticalTypes(self): self.givenMonads(List(1, 2, 3), List(1, 2, 3)) self.ensureMonadsAreEqual()
def monad_function_g(self, x): return List(x * 5, x / 2)
def _find_all_new(condition, location: Path): return List(*[x for x in location.iterdir() if condition(x)])
def test_mplus(self): self.givenMonoids(List(1, 2, 3), List(2, 3, 4)) self.ensure_mconcat_equals(List(1, 2, 3, 2, 3, 4))
def test_left_identity(self): self.givenMonoid(List(1, 2, 3)) self.ensure_zero_plus_monoid_equals(List(1, 2, 3))
def positive_and_negative(x): return List(x, -x)
def add_and_sub(x, y): return List(y + x, y - x)
yield fib1 for fib in fibonacci(20): print(fib, end=' ') print() #monade def positive_and_negative(x): return List(x, -x) positive_and_negative(9) x = List(9) x >> positive_and_negative x = List(1, 2) x >> positive_and_negative @curry def add_and_sub(x, y): return List(y + x, y - x) List(2) >> positive_and_negative >> add_and_sub(3, 4) #data structure user = {
""" fp_task4 just_nothing_list """ from pymonad import Just, List, Nothing, curry @curry def add(x, y): return x + y @curry def add10(x): return add() * Just(10) & x print(add10(List(12, 56, 0, 3))) print(add10(Just(8))) print(add10()(Nothing))
def in3(pos: KnightPos) -> L[KnightPos]: return List(pos) >> moveKnight >> moveKnight >> moveKnight
def testUnitOnList(self): self.assertEqual(List.unit(8), List(8)) self.assertEqual(unit(List, 8), List(8))
def _create_zip(directory: Path): result = _ignore_common( directory ) >> _create_dist_and_copy_files >> _run_pip_install >> _run_zip return List(result.value) if type(result) == Left else List( f'Created zip for {result.value}')
def test_mzero(self): self.givenMonoid(List) self.get_mzero() self.ensure_mzero_is(List())
def execute_shell_command(command: str): # not perfect because execute shell command can throw exceptions subprocess.run([command], shell=True) return List(f'Ran command {command}')
def test_associativity(self): self.givenMonoids(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9)) self.ensure_associativity()
def monad_function_f(self, x): return List(-x, x)
from pymonad import Just, List, Nothing, curry @curry def add(x, y): return x + y def add10(x): return add * Just(10) & x print(add10(List(1, 2, 3, 4, 5, 6))) print(add10(Just(33)))
def remove_dir(directory: Path): try: rmtree(directory) return List(f'Deleted directory {directory}') except FileNotFoundError: return List(f'No delete needed for {directory} - does not exist')