or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

data-types.mdindex.mdinstances.mdmonad-transformers.mdsyntax.mdtype-classes.md
tile.json

tessl/maven-org-typelevel--cats-core-sjs0-6-2-11

Core functional programming abstractions for Scala providing fundamental type classes like Functor, Applicative, and Monad with their instances and syntax extensions.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.typelevel/cats-core_sjs0.6_2.11@2.0.x

To install, run

npx @tessl/cli install tessl/maven-org-typelevel--cats-core-sjs0-6-2-11@2.0.0

index.mddocs/

Cats Core

Cats-core provides essential functional programming abstractions for Scala, serving as the foundation of the Cats ecosystem. It offers a comprehensive collection of type classes, data types, syntax extensions, and instances that enable developers to write pure, composable, and type-safe functional code.

Package Information

  • Package Name: cats-core_sjs0.6_2.11
  • Package Type: maven
  • Organization: org.typelevel
  • Language: Scala 2.11 (Scala.js 0.6 build)
  • Installation: libraryDependencies += "org.typelevel" %%% "cats-core" % "2.0.0"

Core Imports

The most common import brings all syntax and instances into scope:

import cats._
import cats.implicits._

Selective imports for specific functionality:

import cats.{Functor, Applicative, Monad}
import cats.data.{Validated, NonEmptyList, Chain}
import cats.syntax.functor._
import cats.syntax.applicative._

Basic Usage

import cats._
import cats.implicits._
import cats.data._

// Using type classes with syntax
val numbers = List(1, 2, 3)
val doubled = numbers.map(_ * 2)  // Using Functor syntax

// Working with validated data
val valid1: Validated[String, Int] = Validated.valid(42)
val valid2: Validated[String, Int] = Validated.valid(10)
val combined = (valid1, valid2).mapN(_ + _)  // Using Applicative syntax

// Non-empty collections
val nel = NonEmptyList.of(1, 2, 3, 4)
val sum = nel.reduce  // Safe reduction without empty case

// Monad transformers for composing effects
val result: OptionT[List, Int] = for {
  x <- OptionT.liftF(List(1, 2, 3))
  y <- OptionT.pure[List](10)
} yield x + y

Architecture

Cats-core is built around several key architectural concepts:

  • Type Class Hierarchy: A carefully designed hierarchy of abstract type classes (Functor, Applicative, Monad, etc.) that provide increasing levels of power
  • Data Types: Concrete implementations of common functional programming patterns (Validated, Chain, NonEmptyList, etc.)
  • Syntax Extensions: Implicit conversions that add methods to existing types for enhanced ergonomics
  • Instances: Type class implementations for standard library types and cats data types
  • Composability: All abstractions are designed to compose naturally with each other

Capabilities

Type Class Abstractions

Core abstractions that form the foundation of functional programming patterns.

// Functor - map operation
trait Functor[F[_]] {
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

// Applicative - pure and apply operations  
trait Applicative[F[_]] extends Functor[F] {
  def pure[A](x: A): F[A]
  def ap[A, B](ff: F[A => B])(fa: F[A]): F[B]
}

// Monad - flatMap operation
trait Monad[F[_]] extends Applicative[F] {
  def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
  def tailRecM[A, B](a: A)(f: A => F[Either[A, B]]): F[B]
}

Type Class Abstractions

Data Types and Structures

Functional data types that provide safety guarantees and composable operations.

// Validated - accumulating validation  
sealed abstract class Validated[+E, +A]
case class Valid[A](a: A) extends Validated[Nothing, A]
case class Invalid[E](e: E) extends Validated[E, Nothing]

// NonEmptyList - guaranteed non-empty list
final case class NonEmptyList[+A](head: A, tail: List[A])

// Chain - efficient sequence with O(1) append
sealed abstract class Chain[+A]

Data Types and Structures

Monad Transformers

Composable monadic effects that allow stacking of different effect types.

// EitherT - Either over any monad
final case class EitherT[F[_], A, B](value: F[Either[A, B]])

// OptionT - Option over any monad  
final case class OptionT[F[_], A](value: F[Option[A]])

// Kleisli - function composition in monadic context
final case class Kleisli[F[_], A, B](run: A => F[B])

Monad Transformers

Syntax Extensions

Implicit syntax that enhances existing types with functional programming operations.

// Enhanced operations available through implicits
implicit class FunctorOps[F[_], A](fa: F[A])(implicit F: Functor[F]) {
  def map[B](f: A => B): F[B] = F.map(fa)(f)
  def void: F[Unit] = F.void(fa)
  def as[B](b: B): F[B] = F.as(fa, b)
}

implicit class ApplicativeOps[A](a: A) {
  def pure[F[_]](implicit F: Applicative[F]): F[A] = F.pure(a)
}

Syntax Extensions

Type Class Instances

Pre-defined implementations of type classes for standard library types.

// Available instances (imported via cats.implicits._)
implicit val optionMonad: Monad[Option]
implicit val listMonad: Monad[List]  
implicit val eitherMonad[E]: Monad[Either[E, *]]
implicit val function1Monad[A]: Monad[Function1[A, *]]

Type Class Instances

Package Exports

Core type aliases and re-exports available from the cats package:

// Identity and function types
type Id[A] = A
type Endo[A] = A => A
type ~>[F[_], G[_]] = arrow.FunctionK[F, G]

// Kernel re-exports
type Eq[A] = cats.kernel.Eq[A]
type Order[A] = cats.kernel.Order[A]  
type Semigroup[A] = cats.kernel.Semigroup[A]
type Monoid[A] = cats.kernel.Monoid[A]