# Ruchy Examples Cookbook

This directory contains a comprehensive collection of Ruchy code examples demonstrating various language features and programming patterns. Each example is a complete, runnable Ruchy program.

## Basic Examples

### 01. [Basics](01_basics.ruchy)
- Variables and types
- Arithmetic operations
- String operations
- Type conversions
- Mutability

### 02. [Functions](02_functions.ruchy)
- Function definitions
- Parameters and return values
- Type annotations
- Default parameters
- Fat arrow functions (lambdas)
- Higher-order functions
- Recursive functions

### 03. [Control Flow](03_control_flow.ruchy)
- If-else expressions
- Pattern matching with match
- For loops
- While loops
- Break and continue
- Pattern guards

### 04. [Collections](04_collections.ruchy)
- Lists and list operations
- Tuples
- Objects (HashMaps)
- List comprehensions
- Ranges
- Destructuring

### 05. [Strings](05_strings.ruchy)
- String creation and interpolation
- String methods
- String searching and replacing
- String splitting and joining
- Character operations
- Multiline strings

## Intermediate Examples

### 06. [Error Handling](06_error_handling.ruchy)
- Option type
- Result type
- Try-catch blocks
- The ? operator
- Custom error types
- Error propagation

### 07. [Pipeline Operator](07_pipeline_operator.ruchy)
- Basic pipeline operations
- Collection pipelines
- String processing pipelines
- Custom pipeline functions
- Complex data pipelines
- Nested pipelines

### 08. [DataFrames](08_dataframes.ruchy)
- Creating DataFrames
- Filtering and selecting
- Sorting and grouping
- Aggregations
- Joining DataFrames
- Statistical operations

### 09. [Async/Await](09_async_await.ruchy)
- Async functions
- Using await
- Multiple async operations
- Async error handling
- Parallel operations
- Async streams

### 10. [Pattern Matching](10_pattern_matching.ruchy)
- Basic patterns
- Range patterns
- Tuple and list patterns
- Object patterns
- Pattern guards
- Or patterns
- Destructuring

## Advanced Examples

### 11. [File I/O](11_file_io.ruchy)
- Reading and writing files
- Working with directories
- File metadata
- Path operations
- JSON files
- CSV handling
- Binary files

### 12. [Classes and Structs](12_classes_structs.ruchy)
- Struct definitions
- Impl blocks and methods
- Constructors
- Generic structs
- Enums with data
- Traits

### 13. [Iterators](13_iterators.ruchy)
- Map, filter, reduce
- Find operations
- Take and skip
- Zip and enumerate
- FlatMap
- Partition and groupBy
- Custom iterators

### 14. [Macros](14_macros.ruchy)
- Built-in macros
- DataFrame macro
- Custom macro-like functions
- DSL macros
- Derive macros
- Attribute macros
- Conditional compilation

### 15. [Modules](15_modules.ruchy)
- Module definitions
- Public and private functions
- Nested modules
- Using modules
- Module aliases
- Constants

### 16. [Testing](16_testing.ruchy)
- Writing unit tests
- Test runners
- Assertion helpers
- Property-based testing
- Benchmark testing
- Test organization

### 17. [JSON Handling](17_json_handling.ruchy)
- Creating JSON
- Parsing JSON
- JSON validation
- JSON transformation
- JSON Path queries
- Schema validation
- JSON to CSV conversion

### 18. [Algorithms](18_algorithms.ruchy)
- Sorting algorithms (bubble, quick, merge)
- Searching algorithms (binary search)
- Graph algorithms (BFS, DFS)
- Dynamic programming
- Tree algorithms
- String algorithms (KMP)
- Mathematical algorithms

### 19. [Web Scraping](19_web_scraping.ruchy)
- HTTP requests and responses
- HTML parsing and extraction
- CSS selectors
- Data cleaning and validation
- Rate limiting
- Session management

### 20. [CLI Applications](20_cli_apps.ruchy)
- Command-line argument parsing
- Configuration management
- User input and validation
- Progress bars and spinners
- Colored output
- Subcommands

## System Programming Examples

### 21. [Concurrency](21_concurrency.ruchy)
- Actor model implementation
- Message passing
- Thread pools
- Channels and queues
- Supervisor trees
- Deadlock detection

### 22. [Database Operations](22_database.ruchy)
- SQL database connections
- Query builders
- Migrations
- Connection pooling
- Transactions
- ORM patterns

### 23. [Networking](23_networking.ruchy)
- TCP and UDP servers
- HTTP servers and clients
- WebSocket communication
- Protocol implementation
- Load balancing
- Network monitoring

### 24. [Math and Science](24_math_science.ruchy)
- Mathematical computations
- Statistical analysis
- Linear algebra
- Numerical methods
- Scientific computing
- Data visualization

### 25. [Regex and Text Processing](25_regex_text.ruchy)
- Regular expression patterns
- Text parsing and tokenization
- String searching and replacement
- Language processing
- Template engines
- Code generation

### 26. [Cryptography and Security](26_crypto_security.ruchy)
- Encryption and decryption
- Digital signatures
- Hash functions
- Key generation
- Secure random numbers
- Authentication systems

### 27. [Date and Time](27_datetime.ruchy)
- Date and time manipulation
- Timezone handling
- Date arithmetic
- Formatting and parsing
- Calendar operations
- Duration calculations

### 28. [Configuration Management](28_configuration.ruchy)
- Configuration file loading
- Environment variables
- Settings validation
- Hot reloading
- Profile management
- Secret handling

### 29. [Performance Optimization](29_performance.ruchy)
- Benchmarking and profiling
- Memory optimization
- Caching strategies
- Lazy evaluation
- Parallel processing
- Performance monitoring

### 30. [Design Patterns](30_design_patterns.ruchy)
- Singleton and Factory patterns
- Observer and Strategy patterns
- Builder and Decorator patterns
- Command and Template patterns
- Adapter and Proxy patterns
- Chain of Responsibility

## Advanced System Examples

### 31. [Data Validation](31_data_validation.ruchy)
- Input validation and sanitization
- Schema validation
- Custom validators
- Error handling
- Type coercion
- Security validation

### 32. [Logging and Monitoring](32_logging_monitoring.ruchy)
- Structured logging
- Log aggregation
- Metrics collection
- Performance monitoring
- Error tracking
- Health checks

### 33. [GraphQL APIs](33_graphql_api.ruchy)
- GraphQL schema definition
- Resolvers and mutations
- Subscriptions
- DataLoader patterns
- Error handling
- Query optimization

### 34. [Machine Learning](34_machine_learning.ruchy)
- Data preprocessing
- Machine learning algorithms
- Model training and evaluation
- Feature engineering
- Cross-validation
- Prediction pipelines

### 35. [Game Development](35_game_development.ruchy)
- Game state management
- Entity Component System
- Input handling
- Animation systems
- Collision detection
- Game loops

## Cutting-Edge Examples

### 36. [Reactive Programming](36_reactive_programming.ruchy)
- Observable streams
- Event-driven programming
- Backpressure handling
- Stream operators
- Hot vs cold observables
- State management

### 37. [Compiler Plugins](37_compiler_plugins.ruchy)
- AST manipulation
- Code generation
- Procedural macros
- Attribute macros
- Syntax extensions
- Compile-time validation

### 38. [Distributed Computing](38_distributed_computing.ruchy)
- Cluster management
- Distributed data structures
- Consensus protocols
- MapReduce implementation
- Service mesh
- Distributed caching

### 39. [Blockchain and Smart Contracts](39_blockchain_smart_contracts.ruchy)
- Blockchain implementation
- Smart contract development
- Token contracts (ERC-20, NFT)
- Decentralized exchanges
- Oracle systems
- Governance contracts

### 40. [Quantum Computing](40_quantum_computing.ruchy)
- Quantum states and qubits
- Quantum gates and circuits
- Quantum algorithms
- Error correction
- Quantum simulation
- Period finding

## Running the Examples

To run any example:

```bash
ruchy run examples/01_basics.ruchy
```

Or in the REPL:

```bash
ruchy repl
>>> :load examples/01_basics.ruchy
```

## Learning Path

### For Beginners
1. Start with examples 01-05 to learn basic syntax
2. Move to 06 for error handling
3. Try 10 for pattern matching

### For Intermediate Users
1. Explore 07 for functional programming with pipelines
2. Learn 08 for data analysis with DataFrames
3. Study 09 for async programming

### For Advanced Users
1. Dive into 14 for metaprogramming with macros
2. Explore 15 for code organization with modules
3. Master 16 for testing strategies

## Contributing

To add a new example:
1. Create a new `.ruchy` file with a descriptive name
2. Add comprehensive comments explaining the concepts
3. Include various use cases and edge cases
4. Update this README with the new example

## Additional Resources

- [Getting Started Guide](../docs/GETTING_STARTED.md)
- [Language Specification](../SPECIFICATION.md)
- [API Documentation](https://docs.rs/ruchy)