This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Configure ages for country | |
Given A user from BR | |
When getting configuration for drive | |
Then the age should be 18 | |
Given A user from SA | |
When getting configuration for alcohol | |
Then the age does not influence if it is allowed | |
Given A user from US |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultConfiguration = { | |
alcohol: 21, | |
softDrugs: Infinity, | |
hardDrugs: Infinity, | |
drive: 21, | |
adult: 21 | |
} | |
type Configuration = typeof defaultConfiguration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//hard-coded data giving by business (probably) to "play safe" | |
const defaultConfiguration = { | |
alcohol: 21, | |
softDrugs: Infinity, | |
hardDrugs: Infinity, | |
drive: 21, | |
adult: 21 | |
} | |
// ts-magic, creates an interface-like type definition |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function canBuyProduct({ age }: User, { kind }: Product): boolean { | |
const result = age >= this.ageRestriction[kind] | |
// when debugging, we can create and/or tweak data | |
// this way we force the code to flow in the directions that interests the task at hand | |
// remember to revert your changes =D | |
if (true) { | |
logger.warn('front-end exposed user to invalid product') | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is hard-coded data | |
// probably it comes from the business rules | |
const MIN_POINTS = 5 | |
// the argument is a dynamic data | |
// it might come from another place on the codebase | |
// or somewhere else, like a database | |
function calculateFidelity({ type, experiments }: User, products: [Product]) { | |
const points = products.reduce( | |
(total,{ fidelityPoints }) => total + fidelityPoints, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// canBuyProduct is a simple rule | |
function canBuyProduct({ age }: User, { kind }: Product): boolean { | |
const result = age >= this.ageRestriction[kind] | |
if (!result) { | |
logger.warn('front-end exposed user to invalid product') | |
} | |
return result | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*old interface | |
function makeFoo(a: number, b: FooDTO): Foo[] {} | |
*/ | |
//new interface BAD | |
function oldMakeFooDontUseIt(a: number, b: FooDTO): Foo[] {} | |
function newFooMaking(a: FooDTO, b: boolean, c: number): Foo[] {} | |
//new interface GOOD | |
function makeFoo(a: number, b: FooDTO, c: boolean = false): Foo[] {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//the data modifier transforms the class into a record | |
//the constructor and destructor are not relevant for the example but make it easier | |
public data class Person | |
{ | |
string FirstName; | |
string LastName; | |
public Person(string firstName, string lastName) | |
=> (FirstName, LastName) = (firstName, lastName); | |
public void Deconstruct(out string firstName, out string lastName) | |
=> (firstName, lastName) = (FirstName, LastName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(operator first-operand second-operand nth-operand) | |
; like (+ 1 2 3 5 8 13) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my-use-cases", | |
"version": "0.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"my-domain": "0.0.0" | |
} | |
} |
NewerOlder