Skip to content

Instantly share code, notes, and snippets.

View Caballerog's full-sized avatar
:octocat:
live$.pipe(map(person => person.teach(me)),tap(me => me.betterEachDay())))

Carlos Caballero Caballerog

:octocat:
live$.pipe(map(person => person.teach(me)),tap(me => me.betterEachDay())))
View GitHub Profile
import { RecipeComponent } from "./recipe-component";
export class Recipe implements RecipeComponent {
name: string;
components: RecipeComponent[] = [];
constructor(name: string) {
this.name = name;
}
import { RecipeComponent } from "./recipe-component";
export class Ingredient implements RecipeComponent {
name: string;
amount: string;
constructor(name: string, amount: string) {
this.name = name;
this.amount = amount;
}
export interface RecipeComponent {
showDetails(): string;
}
import { Ingredient } from "./ingredient";
import { Recipe } from "./recipe";
const ingredient1 = new Ingredient("Flour", "2 cups");
const ingredient2 = new Ingredient("Eggs", "3");
const recipe = new Recipe("Cake");
recipe.addIngredient(ingredient1);
recipe.addIngredient(ingredient2);
const ingredient3 = new Ingredient("Milk", "1 cup");
import { Ingredient } from './ingredient';
export class Recipe {
name: string;
ingredients: Ingredient[] = [];
recipes: Recipe[] = [];
constructor(name: string) {
this.name = name;
}
export class Ingredient {
name: string;
amount: string;
constructor(name: string, amount: string) {
this.name = name;
this.amount = amount;
}
showDetails(): string {
import { Component } from "./component";
import { Composite } from "./composite";
import { Leaf } from "./leaf";
const leaf1: Component = new Leaf();
const leaf2: Component = new Leaf();
const leaf3: Component = new Leaf();
const composite1: Component = new Composite();
const composite2: Component = new Composite();
import { Component } from "./component";
export class Composite implements Component {
private children: Component[] = [];
// Add a child to the list of children
addChild(child: Component): void {
this.children.push(child);
}
import { Component } from "./component";
export class Leaf implements Component {
operation(): void {
console.log("Leaf operation.");
}
}
export interface Component {
operation(): void;
}