getByPrimaryKey method

Danger<VT, RosterPatternExceptionB> getByPrimaryKey(
  1. PK primaryKey
)

Implementation

Danger<VT, RosterPatternExceptionB> getByPrimaryKey(PK primaryKey) {

    final log = Log(classLocation: RosterPattern, functionLocation: 'getByPrimaryKey');

    return Danger.tryAndCatch(
        () {
            return values.singleWhere(
                (element) => element.primaryKey == primaryKey,
                orElse: () {
                    final primaryKeys = List.generate(length, (index) => elementAt(index).primaryKey);
                    throw Failure(RosterPatternExceptionB(), log.monitor({
                        'primary key': primaryKey,
                        'primary keys': primaryKeys,
                    }));
                },
            );
        },
        log,
    );

}