Skip to content

Commit

Permalink
refactor: get rid of curry
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Aug 17, 2024
1 parent d37f185 commit 7440984
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 95 deletions.
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type { Result, Failure, Success } from '~/utils/adt/result'
export type { Just, Maybe, Nothing } from '~/utils/adt/maybe'
export type { Curry } from '~/utils/composition/curry'
export type { Compose } from '~/utils/composition/compose'
export type { Reduce } from '~/utils/typeclass/foldable'
export type { Pipe } from '~/utils/composition/pipe'
Expand Down
21 changes: 12 additions & 9 deletions src/utils/composition/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* @module compose
*/

import { curry } from '~/utils/composition/curry'
import { reduce } from '~/utils/typeclass/foldable'
/** To pattern match values. */
import { match } from '~/utils/control-flow/match'

/** @typeParam T */
type Fn<T> = (a: T) => T
/** Function that takes a value of type A and returns a value of type A. */
type Fn<A> = (a: A) => A

/** @template T */
export type Fx<T> = ReadonlyArray<Fn<T>>
/** An array of functions {@link Fn}. */
export type Fx<A> = ReadonlyArray<Fn<A>>

/**
* @template T
Expand All @@ -33,7 +33,10 @@ export type Compose = <T>(a: Fx<T>) => (b: T) => T
* types do not match/. That needs to be fixed.
*/
export const compose: Compose = <T>(fx: Fx<T>): ((x: T) => T) => {
const fn = (g: T, f: Fn<T>) => f(g)
const reducer = curry(reduce)(fn)
return (x: T) => reducer(x)(fx)
return match(fx.length)
.with(0, () => (x: T) => x)
.otherwise(() => {
const [head, ...tail] = fx
return (x: T) => compose(tail)(head(x))
})
}
54 changes: 0 additions & 54 deletions src/utils/composition/curry.ts

This file was deleted.

31 changes: 0 additions & 31 deletions test/unit/utils/composition/curry.test.ts

This file was deleted.

0 comments on commit 7440984

Please sign in to comment.