Task

Lazy async computations that always succeed

What is Task?

Task represents a lazy asynchronous computation that always succeeds. Unlike Promise which executes immediately, Task only runs when you explicitly call it. This gives you control over when effects happen and makes testing easier.

// Promise executes immediately:
const data = fetch('/api') // already running!

// Task is lazy:
const data = T.of(() => fetch('/api'))
data() // runs now
Lazy promises
map
chain
parallel
delay
⏱️

Lazy Async

Deferred async computations

Always Succeeds

No error handling needed

🔗

Composable

Chain and combine async work

Parallel Ready

Run multiple tasks concurrently

Task in Action

❌ Eager Promises

const fetchData = fetch('/api/data')

// Executes immediately
// Can't control when it runs
// Hard to test

✅ Task Approach

const fetchData = T.of(() => fetch('/api/data'))

// Lazy evaluation
// Controlled execution
const result = fetchData() // Run when needed

Practice Exercises

1

Basic

Learn about basic in fp-ts task

beginnerStart
2

Map

Learn about map in fp-ts task

beginnerStart
3

Chain

Learn about chain in fp-ts task

beginnerStart
4

Parallel

Learn about parallel in fp-ts task

intermediateStart
5

Delay

Learn about delay in fp-ts task

intermediateStart
6

Practical

Learn about practical in fp-ts task

intermediateStart

Why Learn Task?

⏱️

Master Task

Learn the fundamental concepts and patterns that make Task powerful

💪

6 Exercises

Practice with hands-on exercises from intermediate level

🚀

Production Ready

Apply Task patterns to build robust, type-safe applications