Skip to content

Commit

Permalink
refactor: 💡 inline functions for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lrodrigues-newstore committed Feb 6, 2025
1 parent 8bf35f8 commit 2929e78
Show file tree
Hide file tree
Showing 29 changed files with 65 additions and 151 deletions.
26 changes: 7 additions & 19 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@
"targetDefaults": {
"build": {
"cache": true,
"dependsOn": [
"^build"
],
"outputs": [
"{projectRoot}/lib"
]
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/lib"]
},
"build:cjs": {
"dependsOn": [
"^build:cjs"
],
"dependsOn": ["^build:cjs"],
"cache": true,
"outputs": [
"{projectRoot}/lib"
]
"outputs": ["{projectRoot}/lib"]
},
"build:esm": {
"dependsOn": [
"^build:esm"
],
"dependsOn": ["^build:esm"],
"cache": true,
"outputs": [
"{projectRoot}/lib"
]
"outputs": ["{projectRoot}/lib"]
},
"prepublish": {
"dependsOn": []
Expand All @@ -40,4 +28,4 @@
"dependsOn": []
}
}
}
}
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
"test:coverage": "vitest run --coverage"
},
"lint-staged": {
"**/*.{css,md}": [
"prettier --write"
],
"**/*.{js,json,ts,tsx}": [
"biome check --apply ."
]
"**/*.{css,md}": ["prettier --write"],
"**/*.{js,json,ts,tsx}": ["biome check --apply ."]
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/array/test/sample.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, test } from 'vitest'
import { assert, array, integer, nat, property } from 'fast-check'
import { describe, expect, test } from 'vitest'
import { sample, sampleN } from '../src/index'
import { array, assert, integer, nat, property } from 'fast-check'

describe('sample', () => {
test('undefined if the array is empty', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/bloom-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"bloom filters"
],
"keywords": ["bloom filters"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
5 changes: 1 addition & 4 deletions packages/bloom-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"search",
"bloom filters"
],
"keywords": ["search", "bloom filters"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
4 changes: 2 additions & 2 deletions packages/bloom-search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { range, unique, windowed } from '@pacote/array'
import { BloomFilter, optimal } from '@pacote/bloom-filter'
import { memoize } from '@pacote/memoize'
import type { U64 } from '@pacote/u64'
import { xxh64, type XXHash } from '@pacote/xxhash'
import { type XXHash, xxh64 } from '@pacote/xxhash'
import { findLast } from './array'
import { entries, keys, pick } from './object'
import { EXCLUDE, PHRASE, queryTerms, REQUIRE } from './query'
import { EXCLUDE, PHRASE, REQUIRE, queryTerms } from './query'
import { countIdf } from './tf-idf'

export type PreprocessFunction<Document, Field extends keyof Document> = (
Expand Down
3 changes: 2 additions & 1 deletion packages/bloom-search/src/object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type UnknownRecord = Record<string | number | symbol, unknown>

export const keys = <O extends UnknownRecord>(o: O) => Object.keys(o) as (keyof O)[]
export const keys = <O extends UnknownRecord>(o: O) =>
Object.keys(o) as (keyof O)[]

export const entries = <O extends UnknownRecord>(o: O) =>
Object.entries(o) as [keyof O, O[keyof O]][]
Expand Down
5 changes: 4 additions & 1 deletion packages/bloom-search/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export const EXCLUDE = Symbol('exclude')
export const PHRASE = Symbol('phrase')
export const REQUIRE = Symbol('require')

type SearchTerm = [string, typeof NORMAL | typeof EXCLUDE | typeof REQUIRE | typeof PHRASE]
type SearchTerm = [
string,
typeof NORMAL | typeof EXCLUDE | typeof REQUIRE | typeof PHRASE,
]

const joinPhrase = (term: string) => term.replace(/\s+/g, '_')
const splitPhrase = (term: string) => term.replace(/_+/g, ' ')
Expand Down
5 changes: 1 addition & 4 deletions packages/computus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"easter",
"computus"
],
"keywords": ["easter", "computus"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
6 changes: 1 addition & 5 deletions packages/disposable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"async-dispose",
"dispose",
"explicit resource management"
],
"keywords": ["async-dispose", "dispose", "explicit resource management"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
6 changes: 1 addition & 5 deletions packages/error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"error",
"fp",
"functional programming"
],
"keywords": ["error", "fp", "functional programming"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/flux-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"flux",
"redux",
"actions",
"reducers"
],
"keywords": ["flux", "redux", "actions", "reducers"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
5 changes: 1 addition & 4 deletions packages/get-style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"css",
"styles"
],
"keywords": ["css", "styles"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
4 changes: 1 addition & 3 deletions packages/immutable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"immutability"
],
"keywords": ["immutability"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
4 changes: 1 addition & 3 deletions packages/is-plain-object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"object"
],
"keywords": ["object"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
5 changes: 1 addition & 4 deletions packages/linked-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"immutable",
"linked list"
],
"keywords": ["immutable", "linked list"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
6 changes: 1 addition & 5 deletions packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"memoize",
"fp",
"functional programming"
],
"keywords": ["memoize", "fp", "functional programming"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/option/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"option",
"monad",
"maybe",
"functional programming"
],
"keywords": ["option", "monad", "maybe", "functional programming"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
5 changes: 1 addition & 4 deletions packages/pipe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"pipe",
"composition"
],
"keywords": ["pipe", "composition"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/pixels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"css",
"styles",
"conversion",
"pixels"
],
"keywords": ["css", "styles", "conversion", "pixels"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/react-use-outside/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"react",
"components",
"hoc",
"props"
],
"keywords": ["react", "components", "hoc", "props"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/react-with-props/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"react",
"components",
"hoc",
"props"
],
"keywords": ["react", "components", "hoc", "props"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/result/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"result",
"monad",
"either",
"functional programming"
],
"keywords": ["result", "monad", "either", "functional programming"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
7 changes: 1 addition & 6 deletions packages/shuffle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
"email": "[email protected]",
"url": "https://goblindegook.com"
},
"keywords": [
"shuffle",
"random",
"durstenfeld",
"fisher-yates"
],
"keywords": ["shuffle", "random", "durstenfeld", "fisher-yates"],
"repository": "github:PacoteJS/pacote",
"bugs": {
"url": "https://github.com/PacoteJS/pacote/issues"
Expand Down
5 changes: 4 additions & 1 deletion packages/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export function map<T, R>(fn: (value: T) => R, task: Task<T>): Task<R> {
*
* @returns Flatmapped task.
*/
export function flatMap<T, R>(fn: (result: T) => Task<R>, task: Task<T>): Task<R> {
export function flatMap<T, R>(
fn: (result: T) => Task<R>,
task: Task<T>,
): Task<R> {
return () => task().then((result) => fn(result)())
}

Expand Down
14 changes: 7 additions & 7 deletions packages/task/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, anything, asyncProperty, func } from 'fast-check'
import { describe, expect, test } from 'vitest'
import { anything, assert, asyncProperty, func } from 'fast-check'
import { flatMap, flatten, map, Task } from '../src/index'
import { Task, flatMap, flatten, map } from '../src/index'

test('run a task', async () => {
const task = Task('ok')
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('monad laws', () => {
const direct = Task(fn(value))

expect(await bound()).toEqual(await direct())
})
}),
)
})

Expand All @@ -41,7 +41,7 @@ describe('monad laws', () => {
const direct = Task(value)

expect(await bound()).toEqual(await direct())
})
}),
)
})

Expand All @@ -57,11 +57,11 @@ describe('monad laws', () => {
const t = Task(value)

const left = flatMap(gt, flatMap(ft, t))
const right = flatMap(x => flatMap(gt, ft(x)), t)
const right = flatMap((x) => flatMap(gt, ft(x)), t)

expect(await left()).toEqual(await right())
}
)
},
),
)
})
})
Loading

0 comments on commit 2929e78

Please sign in to comment.