diff --git a/docs/globals.html b/docs/globals.html index b79ce01..58c72cc 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -1981,10 +1981,10 @@

map

  • map<T, Result>(collection: Nullable<T[]>, fn: function): Nullable<Result[]>
  • map<T, Result>(collection: Undefinable<T[]>, fn: function): Undefinable<Result[]>
  • map<T, Result>(collection: Optional<T[]>, fn: function): Optional<Result[]>
  • -
  • map<T, Result>(collection: Dictionary<T>, fn: function): Dictionary<T>
  • -
  • map<T, Result>(collection: Nullable<Dictionary<T>>, fn: function): Nullable<Dictionary<T>>
  • -
  • map<T, Result>(collection: Undefinable<Dictionary<T>>, fn: function): Undefinable<Dictionary<T>>
  • -
  • map<T, Result>(collection: Optional<Dictionary<T>>, fn: function): Optional<Dictionary<T>>
  • +
  • map<T, Result>(collection: Dictionary<T>, fn: function): Dictionary<Result>
  • +
  • map<T, Result>(collection: Nullable<Dictionary<T>>, fn: function): Nullable<Dictionary<Result>>
  • +
  • map<T, Result>(collection: Undefinable<Dictionary<T>>, fn: function): Undefinable<Dictionary<Result>>
  • +
  • map<T, Result>(collection: Optional<Dictionary<T>>, fn: function): Optional<Dictionary<Result>>
  • diff --git a/docs/index.html b/docs/index.html index 0f01bcc..e97b0c1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -112,7 +112,7 @@

    Immutability

    API and documentation

    Documentation is automatically generated from source code and can be found at github pages here.

    -

    You can also play with the library on CodeSandbox.

    +

    You can also play with the library on CodeSandbox.

    You can read the list and sources of all helpers in the src/lib folder here.

    Chaining

    Original idea was to support chaining same way as lodash _.chain works, however after reading diff --git a/src/lib/map.ts b/src/lib/map.ts index baf709d..0c4cb37 100644 --- a/src/lib/map.ts +++ b/src/lib/map.ts @@ -99,7 +99,7 @@ export function map( export function map( collection: Dictionary, fn: (value: T, key: string) => { key: string; value: Result }, -): Dictionary +): Dictionary /** * Maps elements from the collection using mapping function. This function will always return the @@ -119,7 +119,7 @@ export function map( export function map( collection: Nullable>, fn: (value: T, key: string) => { key: string; value: Result }, -): Nullable> +): Nullable> /** * Maps elements from the collection using mapping function. This function will always return the @@ -139,7 +139,7 @@ export function map( export function map( collection: Undefinable>, fn: (value: T, key: string) => { key: string; value: Result }, -): Undefinable> +): Undefinable> /** * Maps elements from the collection using mapping function. This function will always return the @@ -159,7 +159,7 @@ export function map( export function map( collection: Optional>, fn: (value: T, key: string) => { key: string; value: Result }, -): Optional> +): Optional> // NOTE: implementation export function map(collection: any, fn: any): any { diff --git a/src/test/map.test.ts b/src/test/map.test.ts index d2e7a1f..23903d3 100644 --- a/src/test/map.test.ts +++ b/src/test/map.test.ts @@ -32,10 +32,11 @@ describe('map', () => { } const mapFn = (value: string, key: string) => ({ key: key + 'x', - value: key + value, + value: value.length, }) - expect(map(dict, mapFn)).toEqual({ ax: 'aa', bx: 'bb', cx: 'cc' }) + const newDict: Dictionary = map(dict, mapFn) + expect(newDict).toEqual({ ax: 1, bx: 1, cx: 1 }) }) test('is immutable', () => {