Decorator for portation of haskell typeclass ORD
The Ord Interface defines ordering in typescript. The decorator implements the Ordering-Interface. On the other hand it is a library for funtions. Mainly Lists of this interface are used.
There is an es5-translation in the dist-directory. tsc was used for transpiling.
As an addition there is a record-library to calculate some values by lists of IOrds. But it's experimental.
Installation
npm install decorator-ord --save
Usage
Decorator
type TColor = "yellow" | "red"; const carConfig = ; @Ord implements IEq @Ord private age:number; @Ord private color:TColor; { thisage=age; thiscolor=color; } //this is neccessary to ensure the interface boolean; boolean; boolean; boolean;
Notice the Configuration-Object. Objects of car can now be ordered by color and than by age. Be aware that the properties can be any type that support "<",">", are mapped or have IEq implemented.
Using the EQ-Library
sort(cs:IOrd[], config:IOrdConfig):IOrd[]
//sorts listOfCars by carConfig
greater(cs:IOrd[], ref:IOrd, config:IOrdConfig):IOrd[]
//reveals all cars older than 10 years //reveals all red cars older than 10 years
less(cs:IOrd[], ref:IOrd, config:IOrdConfig):IOrd[]
//reveals all yellow cars //reveals all yellow cars younger than 5
Using EqConfig
clone():OrdConfig
let copyOfConfig = carConfig;
ordFields:Array
let newFields:Array<IOrdField> = ; copyOfFieldsordFields; copyOfFieldsordFields = newFields;
eqFields:Array
let newFields:Array<EqField> = ; copyOfFieldseqFields; copyOfFieldseqFields = newFields;
setOrdnialityOfField(name:string, fields:Array, newIndex = 0)
let configCopy = carConfig; configCopy; //Sorts cars with priority age
Using OrdAnd
fuzzyEq(cs:IEq[], refs:IEq[], config:IEqConfig):IEq[]
@OrdAnd
Recorder
It's an experimental technique to extract field-information of lists of Ords. The role model is a recorder. The use is still a bit unclear to me. There are
- CountRecord - frequency of values
- BorderRecord - calculates min and max of values
Tests
npm test
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
Release History
- 0.1.0 Initial release
- 0.1.1 decorator-eq as dependency
- 0.1.2 better transpiling in dist/index.js used
- 0.1.3 split config fields