#functional
25 snippets tagged with #functional
Python Itertools Recipes
Practical itertools patterns for batching, flattening, grouping, and combining iterables.
Best for: Efficient batch processing of large datasets
Java Streams — Filter, Map, Collect
Process collections with Java Streams: filter, map, flatMap, reduce, and collect to lists or maps.
Best for: Transforming and filtering collections
Strategy Pattern with Lambdas
Implement the Strategy pattern using interfaces and Java lambdas for flexible algorithm selection.
Best for: Swappable pricing or discount algorithms
Advanced Streams — Custom Collectors
Advanced Stream operations: custom collectors, flatMap, reduce, teeing, and parallel streams.
Best for: Complex data aggregation and reporting
Functional Interfaces and Lambda Patterns
Use built-in and custom functional interfaces: Predicate, Function, Consumer, Supplier, and composition.
Best for: Composable validation and filtering logic
Method References — All Four Types
Use method references for concise lambda expressions: static, instance, arbitrary object, and constructor.
Best for: Concise functional-style code with method references
Decorator Pattern — OOP and Functional
Implement the decorator pattern both classically and with functional composition for flexible behavior.
Best for: Adding behavior to objects without subclassing
Stream MapReduce and Aggregation
Use streams for MapReduce-style operations: reduce, collect, summarize, and complex aggregations.
Best for: Sales data aggregation and reporting
Checked Exception Wrapping Utilities
Wrap checked exceptions for use in lambdas and streams: sneaky throws, functional wrappers, and Either.
Best for: Using checked-exception methods in lambda expressions
Collections — map, filter, groupBy, and More
Master Kotlin collections: functional transformations, aggregations, grouping, and partition operations.
Best for: Data processing and transformation pipelines
Result Monad — Functional Error Handling
Handle errors functionally with Kotlin Result: map, recover, fold, and chaining fallible operations.
Best for: Type-safe error handling without exceptions
Higher-Order Functions and Lambda Patterns
Compose behavior with higher-order functions: function types, lambda receivers, and functional composition.
Best for: Composable transformation pipelines
Functional Error Handling with Either
Use Either and Option for type-safe error handling: Railway-oriented programming without exceptions.
Best for: Type-safe error handling without exceptions
Functional Error Handling with Either
Implement Either monad for type-safe error handling with map, flatMap, and fold operations.
Best for: Type-safe error handling without exceptions
Collection Transformations and Aggregations
Master Kotlin collection operations: groupBy, partition, associate, zip, windowed, and aggregate.
Best for: Data aggregation and reporting
Kotlin Result API Functional Error Handling
Use Kotlin's built-in Result type for functional error handling: runCatching, map, recover, and fold.
Best for: Functional error handling without try-catch
Functional Composition and Pipelines
Compose functions and build transformation pipelines with Kotlin higher-order functions.
Best for: Data transformation pipelines
Collections Map Filter Fold Operations
Master Scala collections: map, flatMap, filter, fold, groupBy, partition, and zip operations.
Best for: Data transformation and aggregation
For-Comprehensions and Monadic Composition
Use for-comprehensions with Option, Either, Future, and custom monads for elegant composition.
Best for: Chaining optional computations
Type Class Pattern Implementation
Implement the type class pattern in Scala 3: define, provide instances, and use with extension methods.
Best for: Ad-hoc polymorphism without inheritance
Cats Effect IO Monad Basics
Use Cats Effect IO for pure functional effects: sequencing, error handling, resource management.
Best for: Pure functional effect management
ZIO Effect System Basics
Build programs with ZIO: effects, error handling, layers, and concurrent operations.
Best for: Typed error handling with ZIO
Cats Monad Transformers
Use Cats monad transformers: EitherT, OptionT, and StateT for composable effect stacks.
Best for: Composable error handling stacks
Streaming with fs2
Build composable streaming pipelines with fs2: chunks, transformations, concurrency, and resource safety.
Best for: Streaming data processing
Functional State Management
Manage state purely with State monad: stack-based state, random number generation, and game state.
Best for: Pure state transformations