Skip to content

rmnavr/fptk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fptk — functional toolkit for hy-lang

fptk is functional programming language extension for hy-lang.

It is implemented as a curated list of FP-related types/classes, functions and macroses, that can be imported into main scope altogether to always have them at your fingertips.

Having high amount of functions available in main context is inspired by Wolfram Language, in which all (yes, ALL) standard functions are always in the main context.

Intended usage of fptk in hy is:

(import fptk *)     ; import modules, functions and types/classes
(require fptk *)    ; import macros

Topics that fptk covers

Main parts of FPTK are:

Basic operations in FP-style:

  • Math, logic and checks (most checks in fptk end with "Q": like intQ, zerolenQ, etc.)
  • String manipulation and regexes
  • Basic IO (functions like read_file and file_existsQ)
  • Basic benchmarking and debugging

APL-like functions (heavily inspired by funcy lib):

fptk follows funcy approach of providing both generator and list version of most functions (like map and lmap). Also, most functions do not mutate data.

  • Buffed getters (first, second, last, rest, ...)
  • Functional composition, piping, partial application and currying
  • Mapping, filtering and partitioning of sequences

Typing:

  • Reimport of basic types like Any, Optional, etc.
  • Dynamic type checking to an extent that is offered by pydantic

Other quirky things:

  • 1-based index variants of basic getters (don't worry, fptk does not force using them in any way)
  • Inspired by Haskell:
    • macros for lenses library
    • Result type (AKA Either monad) that can be type-checked by pydantic
    • macros for annotating functions via signatures like int -> int => float

Dependencies

Tested with:

Documentation

  1. Cheetsheet — list of all fptk entities with descriptions
  2. Basic macros — description of every fptk macro (except lens-related macros)
  3. Lens related macros — macros that simplify lens definition/application/composition
  4. Result type — API of fptk implementation of Result type

Project status

As of October 2025:

  • full documentation is done
  • testing suite is written
  • some functions require polishing (mostly on adding proper error messsaging)
  • edge cases of fptk macros interactions require more testing

Stable release is not yet reached, small API-breaking changes can happen.

Installation

The easiest way to install fptk is via command:

pip install git+https://github.com/rmnavr/fptk.git@main

About

Functional programming extension for hy lang

Resources

Stars

Watchers

Forks

Packages

No packages published