Skip to content

Instantly share code, notes, and snippets.

@arturaz
Last active December 30, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturaz/06f81fdfc7914205c4325292e3a6f396 to your computer and use it in GitHub Desktop.
Save arturaz/06f81fdfc7914205c4325292e3a6f396 to your computer and use it in GitHub Desktop.
// Pre copy-paste
getAccount(accountId)
.filterMap((account) =>
account.details.owner != modifier
? Some(
"Can't modify a transaction $eventToModifyRef in account $accountId that you don't own: "
"owner=${account.details.owner}, modifier=$modifier"
)
: const Option.none()
)
// pasting into here:
return getAccount(newTxData.accountId)
.filterMap((newAccount) {
final either =
originalAccount.delTx(modifyEventRef, eventToModifyRef, _eventDatas, accountId);
if (either.isLeft) return either.left;
either.rightOrThrow();
newAccount.addTx(eventToModifyRef, newTx, newTxData.total);
return const Option.none();
})
.left;
// after copy paste
return getAccount(newTxData.accountId)
.filterMap((account) =>
account.details.owner != modifier
? Some(
"Can't modify a transaction $eventToModifyRef in account $accountId that you don't own: "
"owner=${account.details.owner}, modifier=$modifier"
)
: const Option.none()
)
.filterMap((newAccount) {
final either =
originalAccount.delTx(modifyEventRef, eventToModifyRef, _eventDatas, accountId);
if (either.isLeft) return either.left;
either.rightOrThrow();
newAccount.addTx(eventToModifyRef, newTx, newTxData.total);
return const Option.none();
})
.left;
// after manual formatting
return getAccount(newTxData.accountId)
.filterMap((account) =>
account.details.owner != modifier
? Some(
"Can't modify a transaction $eventToModifyRef in account ${newTxData.accountId} "
"that you don't own: owner=${account.details.owner}, modifier=$modifier"
)
: const Option.none()
)
.filterMap((newAccount) {
final either =
originalAccount.delTx(modifyEventRef, eventToModifyRef, _eventDatas, accountId);
if (either.isLeft) return either.left;
either.rightOrThrow();
newAccount.addTx(eventToModifyRef, newTx, newTxData.total);
return const Option.none();
})
.left;
// after dartfmt
return getAccount(newTxData.accountId)
.filterMap((account) => account.details.owner != modifier
? Some(
"Can't modify a transaction $eventToModifyRef in account ${newTxData.accountId} "
"that you don't own: owner=${account.details.owner}, modifier=$modifier")
: const Option.none())
.filterMap((newAccount) {
// !!! What is this? Why is this indented LESS than previous line?
final either =
originalAccount.delTx(modifyEventRef, eventToModifyRef, _eventDatas, accountId);
if (either.isLeft) return either.left;
either.rightOrThrow();
newAccount.addTx(eventToModifyRef, newTx, newTxData.total);
return const Option.none();
// !!! What is this? Why is this indented LESS than opening block?
}).left;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment