about summary refs log tree commit diff stats
path: root/html/subx/003trace.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 5211Kartik Agaram2019-05-201-357/+373
* 5033Kartik Agaram2019-03-291-440/+464
* 4989Kartik Agaram2019-02-251-379/+451
* 4982Kartik Agaram2019-02-181-5/+5
* 4891Kartik Agaram2018-12-301-0/+1
* 4890 - new html renderingsKartik Agaram2018-12-291-15/+10
* 4869Kartik Agaram2018-12-161-334/+310
* 4814Kartik Agaram2018-12-011-11/+14
* 4782Kartik Agaram2018-11-261-59/+60
* 4734Kartik Agaram2018-10-281-117/+117
* 4724Kartik Agaram2018-10-241-117/+117
* 4709Kartik Agaram2018-10-171-271/+270
* 4649Kartik Agaram2018-10-021-15/+15
* 4520Kartik Agaram2018-09-261-245/+253
* 4512Kartik Agaram2018-09-231-33/+33
* 4588Kartik Agaram2018-09-221-7/+7
* 4539Kartik Agaram2018-09-071-10/+10
* 4521Kartik Agaram2018-08-131-341/+338
* 4478Kartik Agaram2018-08-041-313/+315
* 4447Kartik Agaram2018-07-271-303/+323
* 4239Kartik Agaram2018-05-081-8/+8
* 4199Kartik K. Agaram2018-01-251-65/+64
* 4161Kartik K. Agaram2017-12-151-9/+9
* 4064Kartik K. Agaram2017-10-141-2/+2
* 4054Kartik K. Agaram2017-10-121-116/+116
* 4052Kartik K. Agaram2017-10-121-0/+463
ion] of patterns) { if (pattern === value || (typeof pattern === 'function' && pattern(value))) { return action(value); } } throw new Error("No match found"); } const isNumber = x => typeof x === 'number'; const isString = x => typeof x === 'string'; const result = match( 42, [1, () => "one"], [2, () => "two"], [isNumber, x => `number: ${x}`], [isString, x => `string: ${x}`] ); console.log(result); // slightly fancier pattern matching const matchObject = (value, ...patterns) => { for (let [pattern, action] of patterns) { if (typeof pattern === 'function' && pattern(value)) { return action(value); } else if (typeof pattern === 'object' && pattern !== null) { let isMatch = true; for (let key in pattern) { if (pattern[key] !== value[key]) { isMatch = false; break; } } if (isMatch) return action(value); } else if (pattern === value) { return action(value); } } throw new Error("No match found"); } const isAdult = person => person.age >= 18; const isChild = person => person.age < 18; const personResult = matchObject( { name: 'Rachel', age: 30 }, [{ name: 'Rachel', age: 30 }, () => "Rachel, 30 years old"], [isAdult, person => `${person.name} is an adult`], [isChild, person => `${person.name} is a child`] ); console.log(personResult); // Basic Matching: Checking if a value directly matches a pattern. // Function Patterns: Uses functions to define more complex matching logic. // Object Patterns: Match objects based on their properties.