The Simplest FP TypeScript Hello World
This lecture demonstrates the simplest possible functional programming example in TypeScript - a pure function that processes data without side effects.
“Simplicity is the ultimate sophistication. A pure function that always returns the same output for the same input is the foundation of predictable, testable code.” - AI Insight
The Simplest Functional Program
Pure Function Example
// The simplest pure function
const greet = (name: string): string => `Hello, ${name}!`;
/**
* Simple greeting function that returns a personalized message.
* @param name - The name to greet
* @returns A greeting string with the provided name
*
* @example
* greet("World") // returns "Hello, World!"
* greet("Alice") // returns "Hello, Alice!"
*/
// Usage
console.log(greet('World')); // "Hello, World!"
console.log(greet('Alice')); // "Hello, Alice!"
Run this example in the TypeScript Playground
From One Function to a Pipeline
The power is not in one pure function; it is that pure functions compose. Add a second one-line function and connect them, output feeding input:
const greet = (name: string): string => `Hello, ${name}!`;
const shout = (message: string): string => message.toUpperCase();
// pipe threads a value left-to-right through each function.
const pipe = <A, B, C>(f: (a: A) => B, g: (b: B) => C) => (a: A): C => g(f(a));
const greetLoudly = pipe(greet, shout);
console.log(greetLoudly('World')); // "HELLO, WORLD!"
greetLoudly is a new function built entirely from two smaller ones — no glue
code, no shared state, no order-of-operations bugs. Because greet and shout
are each pure, their composition is pure too: same input, same output, no side
effects. Every larger functional program in this curriculum is this same move
repeated — small pure functions, composed — so the rest of the course is mostly
learning which small functions and which way to combine them.
🎬 Video Script
INTRO (0:00 - 0:30)
[On camera or voiceover with title card]
“Hey everyone! Today we’re stripping functional programming down to its absolute core. Forget monads, forget complex type theory - we’re starting with the simplest possible example: a pure function that says hello.
By the end of this short video, you’ll understand why this tiny function embodies everything that makes functional programming powerful.”
PART 1: What Makes a Function “Pure”? (0:30 - 1:30)
[Screen: Show the code]
“Here’s our function. Just one line:”
const greet = (name: string): string => `Hello, ${name}!`;“This is a pure function. What does that mean? Two simple rules:
One - Given the same input, it always returns the same output. Call
greet('World')a million times, you’ll get'Hello, World!'a million times. No surprises.Two - It has no side effects. It doesn’t change anything outside itself. No database writes, no global variables mutated, no files modified. It just takes data in, and returns data out.”
PART 2: Why This Matters (1:30 - 2:30)
[Screen: Show usage examples]
“Let’s run it:”
console.log(greet('World')); // "Hello, World!" console.log(greet('Alice')); // "Hello, Alice!"“Now, why should you care? Three reasons:
Predictability - You can reason about this function in isolation. You don’t need to know the state of the entire application to understand what it does.
Testability - Testing is trivial. Input goes in, expected output comes out. No mocking, no setup, no teardown.
Composability - Pure functions are building blocks. You can combine them, chain them, pass them around, and your code stays clean.”
PART 3: The TypeScript Advantage (2:30 - 3:00)
[Screen: Highlight the type annotations]
“Notice the types:
(name: string): string. TypeScript tells us exactly what goes in and what comes out.This is a contract. The compiler enforces it. Try passing a number? Error. Expect a boolean back? Error.
Types plus purity equals confidence. Your code does what it says, and nothing else.”
OUTRO (3:00 - 3:30)
[On camera or voiceover]
“That’s it. The simplest functional program in TypeScript. One pure function.
Every complex functional application - whether it’s using fp-ts, Effect, or any other library - is built on this foundation. Pure functions, composed together.
Start simple. Build up. Thanks for watching, and I’ll see you in the next one.”
📝 Production Notes
- Total runtime: ~3-3.5 minutes
- Visuals: VSCode or TypeScript Playground showing the code
- Tone: Conversational, confident, no jargon
- Call to action: Link to TypeScript Playground in description so viewers can experiment