0.3.13 • Published 8 months ago

generic-handler v0.3.13

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

Generic Handler

Overview

This project provides a flexible and powerful framework for defining and handling generic procedures. It allows you to create procedures with multiple handlers that can be dynamically selected based on predicates. The framework supports various built-in generics, predicates, and combinators to facilitate complex operations.

Features

  • Generic Procedures: Define procedures with multiple handlers.
  • Predicates: Register and use predicates to determine which handler to execute.
  • Combinators: Combine functions and predicates in various ways.
  • Better Set: A more flexible and powerful set implementation.
  • Advice and Wrappers: Modify function inputs and outputs dynamically.

Installation

To install the dependencies, run: bash npm install

Usage

Defining a Generic Procedure

To define a generic procedure, use the construct_simple_generic_procedure function:

import { construct_simple_generic_procedure } from './GenericProcedure';
const myProcedure = construct_simple_generic_procedure("myProcedure", 2, (a, b) => a + b)

Registering Predicates

Before using predicates in your generic procedures, you need to register them:

import { register_predicate } from './Predicates';
const isString = register_predicate('isString', (arg) => typeof arg === 'string');

Defining a Generic Procedure Handler

To define a handler for a generic procedure, use the define_generic_procedure_handler function. Note: You must register the predicate first.

import { define_generic_procedure_handler } from './GenericProcedure';
import { match_args } from './Predicates';
define_generic_procedure_handler(myProcedure, match_args(isString, isString), (a, b) => [a, b]);

Using Predicates in Generic Procedures

You can now use the predicates in your generic procedures:

const result = myProcedure("hello", "world"); // result is ["hello", "world"]
0.3.13

8 months ago

0.3.12

8 months ago

0.3.11

8 months ago

0.3.10

8 months ago

0.3.8

8 months ago

0.3.7

8 months ago

0.3.0

9 months ago

0.3.6

8 months ago

0.3.5

9 months ago

0.2.9

9 months ago

0.3.2

9 months ago

0.3.1

9 months ago

0.3.4

9 months ago

0.3.3

9 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.2.7

10 months ago

0.1.8

10 months ago

0.2.6

10 months ago

0.1.9

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.1.5

10 months ago

0.1.3

10 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.0.9

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.3

11 months ago

0.0.2

12 months ago

0.0.1

12 months ago