Ts Union Versions Save

ADT sum type in typescript

v2.3.0

3 years ago
  • removed empty line 789ff58
  • Merge pull request #14 from twop/match-two be71d34
  • Merge branch 'master' into match-two 3f354a9
  • moved to ava for testing e5d2e7d
  • Merge pull request #12 from twop/dependabot/npm_and_yarn/lodash-4.17.19 58ca340
  • started documenting matchWith API 97d2cfc
  • wip durdling with types b9054c8
  • Co-authored-by: Nathan Shively-Sanders [email protected] a8a8cac
  • Bump lodash from 4.17.15 to 4.17.19 a597be8

https://github.com/twop/ts-union/compare/v2.2.1...v2.3.0

v2.2.1

3 years ago

v2.2.0

3 years ago
  • added pika version script 27dc298
  • reworked internal representation 7c1c417

https://github.com/twop/ts-union/compare/v2.1.1...v2.2.0

There should be no public breaking changes, but I changed the underlying data structure (again!? and again!?) to be {k: string, p0: any, p1: any, p2: any, a: number}, where k is a case name like "CreditCard", p0-p2 passed in parameters and a is how many parameters were passed in. So if you stored the values somewhere (localStorage?) then please migrate accordingly.

const oldShape = { k: 'CreditCard', p: ['Visa', '1111-566-...'] };
const newShape = {
  k: 'CreditCard',
  p0: 'Visa',
  p1: '1111-566-...',
  p2: undefined,
  a: 2,
};

motivation for this is potential perf wins avoiding dealing with (...args) => {...}. The current approach should be more friendly for JIT compilers (arguments and ...args are hard to optimize). That kinda aligns with my local perf results:

old shape

Creation
    baseline: 8.39 ms
    unionize: 17.32 ms
    ts-union: 11.10 ms

Matching with inline object
    baseline: 1.97 ms
    unionize: 5.96 ms
    ts-union: 7.32 ms

Matching with preallocated function
    baseline: 2.20 ms
    unionize: 4.21 ms
    ts-union: 4.52 ms

Mapping
    baseline: 2.02 ms
    unionize: 2.98 ms
    ts-union: 1.69 ms

new shape

Creation
    baseline: 6.90 ms
    unionize: 15.62 ms
    ts-union: 6.38 ms

Matching with inline object
    baseline: 2.33 ms
    unionize: 6.26 ms
    ts-union: 5.19 ms

Matching with preallocated function
    baseline: 1.67 ms
    unionize: 4.44 ms
    ts-union: 3.88 ms

Mapping
    baseline: 1.96 ms
    unionize: 2.93 ms
    ts-union: 1.39 ms

1.2.0

5 years ago
  • now you can define NoData variants with either of<void>() or just of().

Breaking changes from 1.1:

  • t function to define shapes is renamed to of.
  • There is a different underlying data structure. So if you persisted the values somewhere it won't be compatible with the new version.