fromBlockSandwich static method

Danger<ProtectBlockSandwich, CitrusSemanticException> fromBlockSandwich(
  1. BlockSandwich blockSandwich
)

Implementation

static Danger<ProtectBlockSandwich, CitrusSemanticException> fromBlockSandwich(BlockSandwich blockSandwich) {

    final log = Log(classLocation: ProtectBlockSandwich, functionLocation: 'fromBlockSandwich');

    final blockTypeKeyword = blockSandwich.first.second.second;

    if (blockTypeKeyword is! Protect) return Failure(ProtectBlockSandwichExceptionB(), log.monitor({
        'invalid block type keyword': blockTypeKeyword.runtimeType,
    }));

    final startBlockArgumentable = blockSandwich.first.fourth;

    if (startBlockArgumentable is! AccesserableCollection) return Failure(ProtectBlockSandwichExceptionC(), log.monitor({
        'invalid start block argumentable': startBlockArgumentable.runtimeType,
    }));

    final accesserResult = Accesser.fromAccesserableCollection(startBlockArgumentable);
    log.add(accesserResult);
    if (accesserResult is! Success<Accesser, AccesserException>) return Failure(accesserResult.asException, log);

    final source = blockSandwich.source;

    final result = ProtectBlockSandwich(source, accesserResult.wrapped);

    return Success(result, log);

}