Giter Site home page Giter Site logo

21gramconsulting / invertible Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 768 KB

Home Page: https://21gramconsulting.github.io/invertible/

License: MIT License

TypeScript 96.20% JavaScript 3.80%
composition functional functional-programming inverse invertible pipe pipeline pure strict typesafe

invertible's Introduction

Summary

A TypeScript library to allow you to implement strict, strongly typed,invertible (a.k.a. reversible) functions and pipelines (a.k.a. compositions) of pure functions.

Common Use Cases

  • Transalation: Commit-Rollback-style translating between two different types of objects, e.g. between a database model and a domain model.
  • Undo/Redo GUI Features
  • Serialization/Deserialization: e.g. JSON <-> TypeScript objects
  • Encryption/Decryption
  • CLI Programs: Typically you want both pipelines and invertible functions in CLI programs. Pipelines are useful for composing together a series of pure functions to implement the program's logic. Invertible functions are useful for implementing CLI flags that can be used to modify the program's behavior.

Terminology

  • Proverse: A function that takes a value of type A and returns a value of type B.
  • Inverse: A function defined with its Proverse pair in context, that takes a value of type B and returns a value of type A. Therefore, all Inverse functions are also Proverse functions, but not all Proverse functions are Inverse functions.
  • Invertible: A function that has both its Proverse and Inverse defined.
  • Pipeline: A composition of Proverse functions.

Potentially Unfamiliar Conventions

  • Static & Runtime Parity: We at 21Gram always aim to implement runtime aspects of pure types with the same name and same or similar API that represent the very same mental model concepts. For example, you may have an IsNonEmpty type and an IsNonEmpty function for runtime use. The type resolves a true or false type to make conditional typing easier, while the function returns an item is NonEmpty boolean value at runtime.

Examples

For now, please see the tests for examples. We have full 100% coverage and this whole show is for free.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.