TypeScript-STL v2.0.5
New Features
<numeric>
Module <numeric>
has newly implemented in the TSTL by this v2.0 update. special_math
features, who implemented in the v1.7 update, are also belonged to this <numeric>
module.
export interface IComputable<Param, Ret = Param>
{
plus(val: Param): Ret;
minus(val: Param): Ret;
negate(): Ret;
multiplies(val: Param): Ret;
divides(val: Param): Ret;
modules(val: Param): Ret;
}
Mathmatical functions are also implemented in the <numeric>
module. If you want to utilize the algorithm functions with your own computable class, then extends the IComputable
interface and override the methods. Those methods would be used by below operators.
- operations
gcm
lcd
iota
accumulate
inner_product
adjacent_difference
partial_sum
inclusive_scan
&transform_inclusive_scan
exclusive_scan
&transform_exclusive_scan
- operators
plus
&minus
multiplies
&negate
divides
&modules
<functional>
A global function get_uid
has published.
export function get_uid(obj: Object): number;
You can get UID
(unique identifier) of parameter Object
by the function. The get_uid
function has existed since the start of TSTL, however, it's the first time that the feature has published (exported
) for users.
d.ts.map
https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#new---declarationmap
Since TypeScript v2.9 update, emitting declaration map files has been possible. To follow the TypeScript policy, TSTL also starts emitting the d.ts.map
files.
Break Changes
Modular System
Unlike old versions who had merged source files (TS) into only a single JS file, v2.0 update does not merge them. Since the v2.0 update, output JS files are correspondent with each TS source file and they're connected by the the import
statement who follows the modular system (CommonJS
).
Thus, importing TSTL within browser level (<script src="tstl.js"></script>
) is not possible more. When you want to use the TSTL in browser application, then you must use a bundler like browserify
.
By the way, following the modular system, you can take an additional benefit. You can implement partial import by writing detailed path of the target feature like below:
// GLOBAL IMPORT
import * as std from "tstl";
// PARTIAL IMPORT IS ALSO POSSIBLE
import { Vector, TreeMap } from "tstl/container";
import a = require("tstl/iterator");
import b = require("tstl/algorithm");
import c = require("tstl/exception");
import d = require("tstl/functional");
import e = require("tstl/utility");
import sMath = require("tstl/numeric/special_math");
import { sleep_until, shared_timed_mutex } from "tstl/thread";
// SPECIAL FEATURES
import experimental = require("tstl/experimental");
import base = require("tstl/base");
Comparators
https://github.com/samchon/tstl/blob/master/src/functional/comparators.ts
Global comparators in TSTL (used in associative containers), they've changed to compare origin type of parameters using the valueOf()
function since v2.0 update. Also, getting new type Bigint
is also possible.
- Functions
less
equal_to
not_equal_to
,less_equal
,greater
,greater_equal
hash
Also, the comparable interface IComparable
has changed its methods to be required (optional symbol ?
is removed). If you need only partial feature of the IComparable
, then utilize the Pick
type.
interface IComparable<T>
{
equals(obj: T): boolean;
less(obj: T): boolean;
hashCode(): number;
}
declare class Point2D implements Pick<IComparable<MyClass>, "equals"|"less">
{
public x: number;
public y: number;
public equals(p: Point2D): boolean;
public less(p: Point2D): boolean;
}
base.SetContainer & base.MapContainer
export abstract class MapContainer<Key, T,
Unique extends boolean,
Source extends MapContainer<Key, T, Unique, Source>>
extends Container<Entry<Key, T>,
Source,
MapIterator<Key, T, Unique, Source>,
MapReverseIterator<Key, T, Unique, Source>>
{
public abstract insert(pair: IPair<Key, T>): MapContainer.InsertRet<Key, T, Unique, Source>;
public abstract emplace(key: T, val: T): MapContainer.InsertRet<Key, T, Unique, Source>;
}
export namespace MapContainer
{
export type InsertRet<Key, T,
Unique extends boolean,
Source extends MapContainer<Key, T, Unique, Source>>
= Unique extends true
? Pair<MapIterator<Key, T, Unique, Source>, boolean>
: MapIterator<Key, T, Unique, Source>;
}
Since v2.0 update, new generic parameter Unique
has newly added in the base SetContainer
and MapContainer
. Those base containers also have new abstract methods insert
and emplace
had not existed in the earlier versions.
The Unique
parameter would be specified in their sub-class level like UniqueMap
(TreeMap
and HashMap
) or MultiSet
(TreeMultiSet
and HashMultiSet
). Those specifications determine the return types of insert
and emplace
methods, using the conditional type
, new feature of TS v2.9
.
Fixed Errors
- Error on
copy_backward
in<algorithm>
has been fixed. - Error on
empty
in<iterator>
, returning opposite result, has been fixed