Example #1
0
def come_out_roll(dice, status):
    d = dice()
    if sum(d) in (7, 11):
        return Just(("win", sum(d), [d]))
    elif sum(d) in (2, 3, 12):
        return Just(("lose", sum(d), [d]))
    return Just(("point", sum(d), [d]))
Example #2
0
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)
Example #3
0
def come_out_roll(dice, status):
    d = dice()
    if sum(d) in (7, 11):
        return Just(('win', sum(d), [d]))
    elif sum(d) in (2, 3, 12):
        return Just(('lose', sum(d), [d]))
    else:
        return Just(('point', sum(d), [d]))
Example #4
0
def point_roll(dice, status):
    prev, point, so_far = status
    if prev != "point":
        return Just(status)
    d = dice()
    if sum(d) == 7:
        return Just(("craps", point, so_far + [d]))
    elif sum(d) == point:
        return Just(("win", point, so_far + [d]))
    return Just(("point", point, so_far + [d])) >> point_roll(dice)
Example #5
0
def point_roll(dice, status):
    prev, point, so_far = status
    if prev != 'point':
        return Just(status)
    d = dice()
    if sum(d) == 7:
        return Just(('craps', point, so_far+[d]))
    elif sum(d) == point:
        return Just(('win', point, so_far+[d]))
    else:
        return (
            Just(('point', point, so_far+[d]))
            >> point_roll(dice)
        )
Example #6
0
def _run_pip_install(directory: Path):
    if _requires_pip_install(directory):
        with ChangeDir(directory):
            print(f'Running pip install in {directory}')
            execute_shell_command(
                'pip3 install -r requirements.txt -t . >> /dev/null')
    return Just(directory)
Example #7
0
 def hasIdentity(self):
     """ """
     for x in range(self.ORDER):
         if (self.isIdentity(self.__class__(x))):
             if (self.__identity == Nothing):
                 self.__identity = Just(x)
             return True
     return False
Example #8
0
def anscombe():
    """
    >>> d= anscombe()
    >>> d[0]
    [10.0, 8.04, 10.0, 9.14, 10.0, 7.46, 8.0, 6.58]
    >>> d[-1]
    [5.0, 5.68, 5.0, 4.74, 5.0, 5.73, 8.0, 6.89]
    """
    with open("Anscombe.txt") as source:
        data = Just([]) >> read_header(source) >> read_rest(source)
        data = data.getValue()
        return data
Example #9
0
def craps(dice):
    """
    >>> def seven():
    ...    return (3,4)
    >>> craps( seven )
    ('win', 7, [(3, 4)])
    >>> rolls= [(3,3), (2,2), (3,3)]
    >>> def fixed():
    ...    global rolls
    ...    head, *tail = rolls
    ...    rolls= tail
    ...    return head
    >>> craps( fixed )
    ('win', 6, [(3, 3), (2, 2), (3, 3)])
    """
    outcome = (Just(("", 0, [])) >> come_out_roll(dice) >> point_roll(dice))
    print(outcome.getValue())
Example #10
0
def _create_dist_and_copy_files(directory: Path):
    dist_path = _get_dist_path(directory)
    copytree(directory, dist_path)
    return Just(dist_path)
Example #11
0
def _run_zip(directory: Path):
    with ChangeDir(directory):
        zip_name = f'{directory.parent.name}.zip'
        execute_shell_command(f'zip -r {zip_name} . >> /dev/null')
    return Just(directory)
Example #12
0
def check_stack_requirements(stack_data: StackData):
    # also: check whether bucket exists? does require boto3 dependency
    return get_as_path('.') >> partial(_check_template_exists,
                                       stack_data) >> Just(stack_data)
Example #13
0
def check_requirements(lambda_dir):
    return Just(
        lambda_dir
    ) >> _check_root_dir >> _check_dir_has_sub_dirs >> _check_dirs_contain_python
Example #14
0
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)))
Example #15
0
def _get_prefix(stack_data: StackData):
    return Just(
        stack_data.bucket_prefix) if stack_data.bucket_prefix else Just(
            stack_data.stack_name)
Example #16
0
"""
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))
"""
fp_task5

"""
from pymonad import List, Just, Nothing, Maybe

# посадка птиц на левую сторону
to_left = lambda num: lambda x: Nothing if abs(
    (x[0] + num) - x[1]) > 4 else Just((x[0] + num, x[1]))

# посадка птиц на правую сторону
to_right = lambda num: lambda x: Nothing if abs(
    (x[1] + num) - x[0]) > 4 else Just((x[0], x[1] + num))

# банановая кожура
banana = lambda x: Nothing


# отображение результата
def show(Maybe):
    if Maybe == Nothing:
        return print("Will Fall")
    else:
        falled, pole = Maybe.getValue()
        return print(
            "Will not Fall, birds on l.side:{}, birds on r.side:{}".format(
                falled, pole))


begin = lambda: Just((0, 0))
Example #18
0
def get_as_path(value):
    return Just(Path(value))
Example #19
0
 def get_maybe(cls, *args):
     try:
         return Just(super().get(*args))
     except super().DoesNotExist as e:
         return Nothing
Example #20
0
def craps():
    return (
        Just(('', 0, [])) >> come_out_roll(dice)
                          >> point_roll(dice)
    )
Example #21
0
def add10(x):
    return add * Just(10) & x
Example #22
0
def read_header(file):
    _ = file.readline()
    _ = file.readline()
    _ = file.readline()
    return Just([])