JSOS API Overview Core Multimethods Qualified Methods Method Combinators Types Type Graph Meta Types Abstract Types JavaScript Types Data Types Union Types Intersection Types Composite Types Traits Enums Predicate Functions Standard Library Aggregate Types Dicts Tuples Vectors Interfaces Collections Introspection Iteration Stringification

JSOS API Overview

JSOS is divided into two main parts: the core and the standard library.

The core is the foundation of what makes JSOS JSOS. It contains the type system, all the basic predicate functions, multimethods, traits, and structs.

The standard library consists of optional parts of JSOS that are built on top of JSOS's foundation.

Core

These are all exports from the core module of JSOS found in @fed1/jsos.

Multimethods

import { /* <Identifier> */ } from "@fed1/jsos";

Magic Proxies:

Type Identifier Description
Proxy(Object) Generic Assigns new multimethods

Functions & Methods:

Type Identifier Description
JSFunction def Defines a method
JSFunction methods Lists a multimethod's methods
JSFunction prefer Prefers a signature over another
JSFunction undef Removes a method
JSFunction unprefer Removes a signature preference
JSFunction which Calculates applicable method for signature

Predicate Functions:

Type Identifier Description
JSFunction isGeneric Checks if something is a multimethod
JSFunction isMethod Checks if something is a method

Constants & Symbols:

Type Identifier Description
TEnum METHOD_TYPE Method types for methods()
TEnumItem ... MT_AFTER METHOD_TYPE for after methods
TEnumItem ... MT_AROUND METHOD_TYPE for around methods
TEnumItem ... MT_BEFORE METHOD_TYPE for before methods
TEnumItem ... MT_PRIMARY METHOD_TYPE for primary methods
JSSymbol rest Catch-all rest parameter
TEnum RULES Scoring rules for Generic
TEnumItem ... EQUAL RULES constant for equality dispatch
TEnumItem ... IDENTITY RULES constant for identity dispatch
TEnumItem ... ISA RULES constant for is-aispatch
TEnumItem ... PREDICATE RULES constant for predicate dispatch
TEnumItem ... TRAIT RULES constant for trait dispatch

Qualified Methods

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
JSFunction after Adds an after method
JSFunction around Adds an around method
JSFunction before Adds a before method
JSFunction isAfter Checks if something is an 'after' method
JSFunction isAround Checks if something is an 'around' method
JSFunction isBefore Checks if something is a 'before' method
JSFunction isPrimary Checks if something is a primary method

Method Combinators

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
JSFunction genlist Runs all matches, returns all results as array
JSFunction genpipe Runs all matches, pipes results to next, returns last result
JSFunction genplus Runs all matches, sums each result
JSFunction genprogn Runs all matches, returns last result
JSFunction genstd Runs only most specific method (default)

Types

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
Proxy(Object) Type Creates new abstract types
JSFunction setObjectType Set the type of an object
JSFunction observe Adds listener to mutable object
JSFunction isObservable Checks if something is observable

Type Graph

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
JSFunction ancestors Returns a type's ancestors
JSFunction children Returns direct children of a type
JSFunction descendants Returns all descendants of a type
JSFunction isAncestorOf Is A an ancestor of B?
JSFunction isChildOf Is A a child of B?
JSFunction isDescendantOf Is A a descendant of B?
JSFunction isParentOf Is A a parent of B?
JSFunction parents Returns a type's parents
JSFunction specificity Calculates how far a type is from TAny

Meta Types

import { /* <Identifier> */ } from "@fed1/jsos";

Meta types are the types of types.

Type Identifier Description
TType TAbstractType
TAbstractType TDataType
TAbstractType TDependentType
TAbstractType TIntersectionType
TAbstractType TJSType
TAbstractType TType
TAbstractType TUnionType
TAbstractType TIntersectionType

Abstract Types

import { /* <Identifier> */ } from "@fed1/jsos";

Abstract types are types that cannot be instantiated, but they can be parameterized and be the parents of concrete types.

Type Identifier Description
TAbstractType TAny
TAbstractType TBoolean
TAbstractType TFloat
TAbstractType TInt
TAbstractType TNothing
TAbstractType TNumber
TAbstractType TReal
TAbstractType TString

JavaScript Types

import { /* <Identifier> */ } from "@fed1/jsos";

These types integrate JavaScript's types seamlessly into JSOS's type system.

Type Identifier Description
TJSType JSArray JavaScript's Array
TJSType JSBigInt JavaScript's bigint
TJSType JSBoolean JavaScript's boolean
TJSType JSFunction JavaScript's function
TJSType JSMap JavaScript's Map
TJSType JSNull JavaScript's null
TJSType JSNumber JavaScript's number
TJSType JSObject JavaScript's object
TJSType JSSet JavaScript's Set
TJSType JSString JavaScript's string
TJSType JSSymbol JavaScript's symbol
TJSType JSWeakMap JavaScript's WeakMap
TJSType JSWeakRef JavaScript's WeakRef
TJSType JSWeakSet JavaScript's WeakSet

Data Types

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
TAbstractType TGeneric The type of multimethods
TDataType TTrait The type of traits

Union Types

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
TAbstractType TUnionType The type of type unions
JSFunction isUnion Checks if something is a TUnionType
JSFunction Union Creates a union of types

Intersection Types

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
TAbstractType TIntersectionType The type of type intersections
JSFunction isIntersection Checks if something is a TIntersectionType
JSFunction Intersection Creates an intersection of types

Composite Types

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
Proxy(Function) Struct Creates a complex type
Proxy(Function) MStruct Creates a mutable complex type
JSFunction isStructType Checks if something is a struct type
JSFunction isMStructType Checks if something is a mutable struct type

Traits

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
TDataType TTrait The type of traits
Proxy(Object) Trait Creates new traits
JSFunction hasTrait Checks whether a type implements a trait

Enums

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
TAbstractType TEnum Type of enums
TAbstractType TEnumItem Type of enum items
Proxy(Function) Enum Assigns values of type TEnum
JSFunction keyOf Returns an enum item's key
JSFunction valueOf Returns an enum item's value

Predicate Functions

import { /* <Identifier> */ } from "@fed1/jsos";
Type Identifier Description
JSFunction isA a, b Checks if a is a b
JSFunction isAfter a Checks if a is an 'after' method
JSFunction isAncestorOf a, b Checks if a is an ancestor to b
JSFunction isAround a Checks if a is an 'around' method
JSFunction isArray a Checks if a is a JS array
JSFunction isBefore a Checks if a is a 'before' method
JSFunction isBigInt a Checks if a is a JS bigint value
JSFunction isBoolean a Checks if a is a JS boolean value
JSFunction isChildOf a, b Checks if a is a child of b
JSFunction isDependentType a Checks if a is a TDependentType
JSFunction isDescendantOf a, b Checks if a is a descendant of b
JSFunction isEqual a, b Checks if a is deep equal to b
JSFunction isFunction a Checks if a is a JS function
JSFunction isGeneric a Checks if a is a multimethod
JSFunction isIdentical a, b Checks if a is identical to b
JSFunction isIntersection a Checks if a is a TIntersectionType
JSFunction isMap a Checks if a is a JS Map object
JSFunction isMethod a Checks if a is a JSOS method
JSFunction isMStructType a Checks if a is a mutable struct type
JSFunction isNull a Checks if a is null
JSFunction isNumber a Checks if a is a JS number
JSFunction isObject a Checks if a is a JS object
JSFunction isObservable a Checks if a can be observed
JSFunction isParentOf a, b Checks if a is a parent of b
JSFunction isPrimary a Checks if a is a primary method
JSFunction isPrimitive a Checks if a is a primitive value
JSFunction isRegExp a Checks if a is a JS regular expression
JSFunction isSet a Checks if a is a JS Set object
JSFunction isString a Checks if a is a JS string
JSFunction isStructType a Checks if a is a struct type
JSFunction isSymbol a Checks if a is a JS symbol
JSFunction isType a Checks if a is a JSOS type object
JSFunction isUndefined a Checks if a is undefined
JSFunction isUnion a Checks if a is a TUnionType
JSFunction isWeak a Checks if a is a weak JS data type
JSFunction isWeakMap a Checks if a is a JS WeakMap object
JSFunction isWeakRef a Checks if a is a JS WeakRef object
JSFunction isWeakSet a Checks if a is a JS WeakSet object

Standard Library

Aggregate Types

Aggregate types are concrete types that can contain multiple values. Of these, JSOS's core only contains Struct and MStruct. But the following additional aggregate types are available in the standard library.

Dicts

import { /* <Identifier> */ } from "@fed1/jsos/dicts";
Type Identifier Description
TAbstractType TDict Type of dictionaries
TAbstractType TMDict Type of mutable dictionaries
TAbstractType TDictDescriptor Type of the descriptor object created by Dict/MDict
JSfunction Dict Creates dictionaries
JSfunction MDict Creates mutable dictionaries

Tuples

import { /* <Identifier> */ } from "@fed1/jsos/tuples";
Type Identifier Description
TAbstractType TTuple The type of all tuples
JSFunction Tuple Creates a tuple

Vectors

import { /* <Identifier> */ } from "@fed1/jsos/vectors";
Type Identifier Description
TAbstractType TDict Type of vectors
TAbstractType TMDict Type of mutable vectors
TAbstractType TDictDescriptor Type of descriptor objects created by Vector/MVector
JSfunction Dict Creates vectors
JSfunction MDict Creates mutable vectors

Interfaces

Interfaces in JSOS are comprised of traits and multimethods.

Multimethods can form an ad-hoc interface, while traits are types that formalize these interfaces by grouping related multimethods together under a common name.

Any concrete type can implement a trait using its .implement() method. When a type implements a trait, the trait can be used in multimethod signatures and then matches all the types that implement the trait.

Collections

import { /* <Identifier> */ } from "@fed1/jsos/collections";
Type Identifier Description
TGeneric at
TGeneric entries
TGeneric has
TGeneric keys
TGeneric length
TGeneric size
TGeneric values

Introspection

import { /* <Identifier> */ } from "@fed1/jsos/introspection";
Type Identifier Description
TGeneric explain Creates a string explaining its argument

Iteration

import { /* <Identifier> */ } from "@fed1/jsos/iteration";
Type Identifier Description
TTrait Iterable Trait for iterable types
TGeneric iterate Iterates a sequence step by step
TGeneric each Applies a function to each item in a sequence
TGeneric map Creates a new sequence by applying a function to each item of a sequence

Stringification

import { /* <Identifier> */ } from "@fed1/jsos/stringification";
Type Identifier Description
TTrait Stringifyable Trait for types that can be converted to string
TGeneric stringify Multimethod for converting stuff to string