class PeriodAttrtype(object):
    DurationPeriod = constructor(
        start_date=attr.ib(validator=attr.validators.instance_of(date)),
        duration=attr.ib(validator=attr.validators.instance_of(str)))
    DatePeriod = constructor(
        start_date=attr.ib(validator=attr.validators.instance_of(date)),
        end_date=attr.ib(validator=attr.validators.instance_of(date)))
class Transform(object):
    Int_To_String = constructor(
        i=attr.ib(validator=attr.validators.instance_of(int)),
        s=attr.ib(validator=attr.validators.instance_of(str)))
    String_To_Int = constructor(
        s=attr.ib(validator=attr.validators.instance_of(str)),
        i=attr.ib(validator=attr.validators.instance_of(int)))
Ejemplo n.º 3
0
class MyType(object):
    # constructors specify names for their arguments
    MyConstructor = constructor('x')
    AnotherConstructor = constructor('x', 'y')

    # You can also make use of any feature of the attrs
    # package by using attr.ib in constructors
    ThirdConstructor = constructor(
        # one=attr.ib(default=42),
        # ValueError: No mandatory attributes allowed after an attribute with a default value or factory
        two=attr.ib(validator=attr.validators.instance_of(int)),
        one=attr.ib(default=42))
Ejemplo n.º 4
0
class Maybe(object):
    Nothing = constructor()
    Just = constructor('val')

    # fmap: (a -> b) -> (Maybe a -> Maybe b)
    # f: a -> b
    # return: Maybe<a> -> Maybe<b>
    @staticmethod
    def fmap(f):
        def mf(ma):
            return ma.map(f)

        return mf

    # join: Maybe<Maybe<a>> -> Maybe<a>
    # mma: Maybe<Maybe<a>>
    # return: Maybe<a>
    @staticmethod
    def join(mma):
        return NOTHING if mma == NOTHING else mma.val

    # ret: a -> Maybe<a>
    @staticmethod
    def ret(a):
        return Just(a)

    # bind: Maybe<a> -> (a -> Maybe<b>) -> Maybe<b>
    # ma: Maybe<a>
    # f: a -> Maybe<b>
    # return Maybe<b>
    @staticmethod
    def bind(ma, f):
        return Maybe.join(ma.map(f))
        # return Maybe.join(Maybe.fmap(f)(ma))

    # flatmap: (a -> mb) -> mb
    # f: a -> mb
    def flatmap(self, f):
        return Maybe.join(self.map(f))

    # f: a -> Maybe<b>
    # g: b -> Maybe<c>
    # return a -> Maybe<c>
    @staticmethod
    def fish(f, g):
        def h(a):
            return Maybe.bind(f(a), g)

        return h
Ejemplo n.º 5
0
class Result:
    Failure = constructor('msg')
    Success = constructor('value')
Ejemplo n.º 6
0
class ErrorReason(object):
    """A reason for a step to be in a RETRY or FAILURE state."""
    Exception = constructor('exc_info')
    String = constructor(reason=attr.ib(validator=instance_of((unicode, str))))
    Structured = constructor('structure')
    UserMessage = constructor('message')
Ejemplo n.º 7
0
class ConvergenceIterationStatus(object):
    """Result of a single convergence iteration."""
    Stop = constructor()  # Stop converging. Dirty flag can be deleted
    Continue = constructor()  # Continue converging. Don't delete flag.
    GroupDeleted = constructor()  # Group disappeared; force-delete dirty flag.
class Implementation(object):
    Sumtype = constructor(sum_type=attr.ib(
        validator=attr.validators.instance_of(PeriodSumtype)))  #,
    #        impl=attr.ib(validator=attr.validators.instance_of(str)))
    Attrtype = constructor(attr_type=attr.ib(
        validator=attr.validators.instance_of(PeriodAttrtype)))  #,
class PeriodSumtype(object):
    DurationPeriod = constructor('start_date', 'duration')
    DatePeriod = constructor('end_date', 'start_date')
Ejemplo n.º 10
0
class Int_Or_String(object):
    Int = constructor(i=attr.ib(validator=attr.validators.instance_of(int)))
    String = constructor(s=attr.ib(validator=attr.validators.instance_of(str)))
Ejemplo n.º 11
0
def _clike_struct(*fields: str):
    return constructor(*fields)
Ejemplo n.º 12
0
def _unit_struct():
    return constructor()
Ejemplo n.º 13
0
def _tuple_struct():
    return constructor(**{TUPLE_DATA: attr.ib(type=tuple)})
Ejemplo n.º 14
0
class MyType(object):
    """ Name and Number """
    NamedNum = constructor('name', 'num')
    AnonymousNum = constructor('num')
Ejemplo n.º 15
0
class PeriodAttr(object):
    Duration = constructor(dur_period=attr.ib(
        validator=attr.validators.instance_of(DurationPeriod)))
    Date = constructor(dat_period=attr.ib(
        validator=attr.validators.instance_of(DatePeriod)))