$ show xebia-functional/fetch
Fetch is a Scala library for simple and efficient data access, built on cats-effect. It provides a monadic abstraction (`Fetch[F, A]`) that automatically optimizes data fetching through batching, caching, deduplication, and parallel execution. Users define data sources by implementing the `DataSource` trait, specifying how to fetch individual identities or batches. The library then composes fetches using standard monadic and applicative combinators, transparently batching requests to the same source and running independent fetches concurrently. It supports custom caches, optional fetches, error handling, and debugging via a separate `fetch-debug` module. The architecture is a pure library with no runtime dependencies beyond cats-effect, making it suitable for both JVM and Scala.js. Key entry points include `Fetch.apply`, `Fetch.run`, `Fetch.runLog`, and `Fetch.runCache`. External dependencies are minimal: cats-effect, cats-core, and scalatest for testing.
The LLM identified 2 files worth highlighting for reuse:
Defines the `DataCache` trait for pluggable caching in Fetch, along with `InMemoryCache` as a default implementation. The trait is minimal and generic, allowing users to implement custom caches (e.g., Redis, forgetful). The `InMemoryCache` is an immutable map-based cache that can be prepopulated via `InMemoryCache.from`. This component is self-contained and can be extracted for use in other projects requiring a similar caching abstraction.
A standalone pretty-printing library based on Wadler's and Hughes' work, implemented in Scala. It provides a `Document` type with combinators for text, breaks, nesting, and grouping, and a `format` method that renders to a `Writer` with optimal line breaks. This is a high-quality, reusable component that can be extracted into its own project for any pretty-printing needs.