Fp4ts
Zero-dependency, purely functional library for effectful programming in Typescript
Install / Use
/learn @fp4ts/Fp4tsREADME
fp4ts
Welcome to fp4ts! Fp4ts is a zero-dependency, purely functional library that attempts to provide idiomatic support for lazy, safe, and performant functional programming in Typescript by porting a portion of the Typelevel and Haskell ecosystems.
The project is currently under development and is not intended to be used in production.
Project Structure
Fp4ts is fairly large and offers multiple packages:
-
@fp4ts/coreThe library implementing basic building blocks and utilities used across the rest of the packages, namely the HKT abstraction. -
@fp4ts/catsPort of the Cats library providing basic data types, collections and fundamental abstraction (e.g., Functor, Monad) used for functional programming. It also provides a set of laws, to verify correctness of those implementations.@fp4ts/cats-kernelSmall set of basic types and type classes (included)@fp4ts/cats-coreMajority of the type classes and basic data types (included)@fp4ts/cats-lawsLaws for testing type class instances/implementations@fp4ts/cats-profunctorProfunctor type classes, data type, and instances for core types@fp4ts/cats-profunctor-lawsLaws for testing profunctor type classes@fp4ts/cats-arrowArrow type classes, data type, and instances for core types@fp4ts/cats-arrow-lawsLaws for testing arrow type classes@fp4ts/cats-test-kitJest integration for testing type class instances and collection of builtin arbitraries for provided data types@fp4ts/freeFree structures
-
@fp4ts/collectionsBasic collections such asList,LazyList,OrdMap, andOrdSet.@fp4ts/collections-coreImplementation of the collection data types (included)@fp4ts/collections-test-kitSet offast-checkarbitraries for the collections.
-
@fp4ts/mtlMonad Transformer Library@fp4ts/mtl-coreSet of type classes and transformer data types (included)@fp4ts/mtl-lawsSet of laws for testing monad transformer implementations
-
@fp4ts/effectPort of the Cats Effect library providing data types, fundamental abstraction (e.g., MonadCancel, Async) used for effectful and async functional programming. It also provides a set of laws, to verify correctness of those implementations.@fp4ts/effect-kernelSet of type classes for describing effectful computations/data types (included)@fp4ts/effect-coreImplementations of theIOandSyncIOdata types (included)@fp4ts/effect-stdImplementations of the standard effectful data types such asQueueorSemaphore(included)@fp4ts/effect-lawsLaws for testing type class instances/implementations@fp4ts/effect-test-kitJest integration for testing type class instances and collection of builtin arbitraries for provided data types
-
@fp4ts/fusedPartial port of the fused-effects providing algebraic, higher-order, extensible effects with a standard library compatible with@fp4ts/cats-mtl.@fp4ts/fused-kernelSet of type classes and primitives for defining effect carriers as well as interpreters (included)@fp4ts/fused-coreDefinition of standard effect types (included)@fp4ts/fused-stdLibrary of standard effect carriers using@fp4ts/cats-mtl(included)
-
@fp4ts/httpPort of the http4s library, providing minimal functional interface for building HTTP services. In addition to the http4s, this port also includes Servant-like dsl for API declaration.@fp4ts/http-coreImplementation of the basic data types for building HTTP services, such asRequest<F>,Response<F>, and more (included)@fp4ts/http-clientDefinition of theClient<F>type and its default implementation@fp4ts/http-serverDefinition of theServer<F>type and a set of middlewares@fp4ts/dslServant-like library for defining APIs@fp4ts/dsl-clientDerivation of the clients for APIs defined using@fp4ts/dsl@fp4ts/dsl-serverDerivation of the servers for APIs defined using@fp4ts/dsl@fp4ts/node-clientNode.js bindings for the HTTP clients@fp4ts/node-serverNode.js bindings for the HTTP servers@fp4ts/test-kitLibrary for testing HTTP services and clients@fp4ts/test-kit-nodeNode bindings for testing HTTP services and clients
-
@fp4ts/loggingLogging library inspired by log4cats, purescript-logging, and zio-logging. The library provides brackets usingWriter,WriterTandConsoletype classes.@fp4ts/logging-kernelSet of type classes and default implementation for logging (included)@fp4ts/logging-coreImplementation for standard loggers (included)
-
@fp4ts/opticsPort of the lens library, a Haskell optics library providing families of lenses, isomorphisms, folds, traversals, setters, and getters.@fp4ts/optics-coreImplementation of the common regular, index preserving and indexed optics (included)@fp4ts/optics-derivationBinding for deriving common optics from@fp4ts/schemadefinitions (included)@fp4ts/optics-stdImplementation of standard optics (included)@fp4ts/optics-lawsSet of laws to verify properties of the optics
-
@fp4ts/parseAdaptation of the Parsec library, a parser combinator library with polymorphic input and evaluation effect type. By default, the library provides tools for text parsing. Parsec was chosen instead of the cats-parse existing in the Typelevel ecosystem for the simplicity of the implementation, support for polymorphic input types and contrary to the decision made in cats-pase, unification of parsers guaranteed to consume input and ones that do not.@fp4ts/prase-kernelType classes for defining tokens and streams of values (included)@fp4ts/parse-coreImplementation of the parse and its default combinators (included)@fp4ts/parse-textImplementation of the text-parses and helpers for their usage (included)
-
@fp4ts/schemaThe library for describing types of Kind-0 and Kind-1, with derivation capabilities for common typeclasses such asEq,Functor,Foldable, and more. Inspired by io-ts, shapeless, and kittens.@fp4ts/schema-kernelType classes for describing types for derivations of Kind-0 and Kind-1 types (included)@fp4ts/schema-coreDerivable data types for validation, encoding and decoding of types (included)@fp4ts/schema-derivationDerivation of data type constructors (included)@fp4ts/schema-jsonJSON-specific encoders and decoders@fp4ts/schema-lawsSet of laws for codable data types@fp4ts/schema-test-kitSet of arbitraries for testing schemable types
-
@fp4ts/sqlPartial port of the doobie library providing functional interface for SQL databases.@fp4ts/sql-coreCore data types for describing communication with RDMS (included)@fp4ts/sql-mariadbDriver for MariaDB@fp4ts/sql-pgDriver for Postgres@fp4ts/sql-sqliteDriver for SQLite
-
@fp4ts/streamPort of the FS2 library for purely functional, effect-ful, and polymorphic stream processing.@fp4ts/stream-coreDefinition of basicStream,PullandChunktypes, and related type classes for compiling the effectful streams (included)@fp4ts/stream-ioNode.js interop providing bindings forReadable,Writableand console IO
Each of the listed packages is released separately. However, packages which are
marked as included can be consumed by installing the root module. For example,
for consuming anything from @fp4ts/cats-kernel or @fp4ts/cats-core one can
just install @fp4ts/cats and:
import { Ord, None, Some } from '@fp4ts/cats';
import { OrdMap } from '@fp4ts/collections';
const xs: [string, number][] = [['a', 42], ['b', 43]];
const x: OrdMap<string, string> = OrdMap
.fromArray(xs, Ord.fromUniversalCompare())
.collect(v => v % 2 === 0 ? Some(`${v}`) : None)
...
Versioning
As the project is under development and not intended to be used in production,
all of the packages are versioned as 0.0.x without any API stability guarantees.
Examples
- John De Goes' FP to the Max
- Todo API implemented using the Servant-style API dsl
License
The MIT License (MIT)
Copyright (c) 2021-2023 Peter Matta.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is f
