Skip to content

Commit

Permalink
Removed unused utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoci committed Sep 28, 2023
1 parent 69fe376 commit 8d2f498
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/either/serializer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { constant } from '../lambda/lambda'
import { Serializable, Variants } from '../types'
import { isEither } from './either'

Expand Down Expand Up @@ -33,6 +32,6 @@ const toJSON = () => {
}

export const createSerializable = <T>(variant: Variants, value: T): Serializable => ({
toString: constant(() => wrap(variant, stringify(value))),
toString: () => wrap(variant, stringify(value)),
toJSON,
})
28 changes: 3 additions & 25 deletions src/lambda/lambda.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { chunk, maybeFirst, maybeLast, constant, repeat, rotate } from './lambda'
import { maybeFirst, maybeLast, constant, repeat } from './lambda'

describe('Lambda', () => {
describe('Once', () => {
describe('constant', () => {
it('runs function only once', () => {
const fn = jest.fn().mockReturnValue('value')
const wrapped = constant(fn)
Expand All @@ -14,7 +14,7 @@ describe('Lambda', () => {
})
})

describe('Repeat', () => {
describe('repeat', () => {
it('runs a function n times', () => {
const fn = jest.fn().mockReturnValue('value')
const times = 5
Expand All @@ -27,28 +27,6 @@ describe('Lambda', () => {
})
})

describe('Rotate', () => {
it('rotates an array', () => {
const arr = [1, 2, 3]
const positions = 2

const result = rotate(positions, arr)

expect(result).toEqual([3, 1, 2])
})
})

describe('Chunk', () => {
it('chunks an array', () => {
const arr = [1, 2, 3]
const size = 2

const result = chunk(size, arr)

expect(result).toEqual([[1, 2], [3]])
})
})

describe('maybeFirst', () => {
describe('when array is empty', () => {
const array: number[] = []
Expand Down
5 changes: 0 additions & 5 deletions src/lambda/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ const createArray = (times: number): undefined[] => Array(times).fill(undefined)

export const repeat = <T>(times: number, factory: (index: number) => T) => createArray(times).map((_, i) => factory(i))

export const rotate = <T>(n: number, arr: T[]): T[] => arr.slice(n, arr.length).concat(arr.slice(0, n))

export const chunk = <T>(size: number, arr: T[]): T[][] =>
repeat(Math.ceil(arr.length / size), (index) => index * size).map((begin) => arr.slice(begin, begin + size))

export const noop = () => {}

export const maybeFirst = <T>(array: T[]): Maybe<T> => maybe(array[0])
Expand Down

0 comments on commit 8d2f498

Please sign in to comment.