...

/

Solution Review: Create a Mini DSL

Solution Review: Create a Mini DSL

Learn to create a mini DSL.

We'll cover the following...

Solution

Press + to interact
const createFlight = (typeOfFlight: KindOfFlight, date: Date) => (airplane: Airplane): O.Option<Flight> => {
if (!typeOfFlight || !date || !airplane) {
return O.none;
}
switch (typeOfFlight) {
case 'ARRIVAL': {
return O.some({
type: 'Arrival',
arrivalTime: date,
airplane,
});
}
case 'DEPARTURE': {
return O.some({
type: 'Departure',
departureTime: date,
airplane,
});
}
default:
const _exhaustiveCheck: never = typeOfFlight;
return _exhaustiveCheck;
}
};
console.log(createFlight("ARRIVAL",new Date())({seats:100}));

Explanation

  • Lines
...