Пример #1
0
 def split():
     for i, d in enumerate(dtypes):
         data = zdata[i]
         if issubclass(d, Queue):
             yield ccat(data, zlast[:d.lvl]) | Queue[data.dtype, d.lvl]
         else:
             yield data
Пример #2
0
def unionmap(din,
             *,
             f,
             fdemux=demux_ctrl,
             fmux=mux,
             balance=None,
             mapping=None,
             use_dflt=True):

    if mapping:
        fdemux = fdemux(mapping=mapping)
        fmux = fmux(mapping=mapping)

    demux_dout = din | fdemux
    ctrl = demux_dout[0]
    branches = demux_dout[1:]

    dout = []
    for i, fd in enumerate(f):
        if fd is None:
            if balance is None:
                dout.append(branches[i])
            else:
                dout.append(branches[i] | balance)
        else:
            dout.append(branches[i] | fd)

        if dout[-1] is None or isinstance(dout[-1], tuple):
            ret = 'none' if dout[-1] is None else f'{len(dout[-1])} outputs'
            raise TypeMatchError(
                f'Gear "{fd}" passed to the unionmap should have a single output, but returned {ret}'
            )

    # Situation where there is a default branch because of mapping
    if len(branches) == len(dout) + 1 and mapping is not None:
        if use_dflt:
            dout.append(branches[-1])
        else:
            branches[-1] | shred

    elif len(branches) > len(dout):
        raise Exception

    if balance is not None:
        ctrl = ctrl | balance

    if len(dout) == 1:
        return ccat(*dout, ctrl) | Union
    else:
        return fmux(ctrl, *dout)
Пример #3
0
def cart_wrap_with(sync, din):
    din_cart = cart(sync, din)

    return ccat(din_cart['data'][1], din_cart['eot']) | Queue
Пример #4
0
def when_single(cond, din, *, f):
    return ccat(din, cond) | Union | filt(fixsel=1) | f
Пример #5
0
def some(din) -> Maybe['din']:
    return ccat(din, Bool(True)) >> Maybe[din.dtype]