Fix exports for fold

This commit is contained in:
Eric Rumsey 2025-06-13 11:27:35 -05:00
parent b71d39c845
commit 6f55c892c2
3 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "fp-lib", "name": "fp-lib",
"version": "1.0.3", "version": "1.0.4",
"description": "Zero-dependency functional programming library optimized for Bun", "description": "Zero-dependency functional programming library optimized for Bun",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",

View File

@ -74,7 +74,7 @@ export const eitherChain =
* @param onRight - Function to handle Right case * @param onRight - Function to handle Right case
* @returns A function that takes an Either and returns the folded value * @returns A function that takes an Either and returns the folded value
*/ */
export const fold = export const foldEither =
<A, E, B>(onLeft: (e: E) => B, onRight: (a: A) => B) => <A, E, B>(onLeft: (e: E) => B, onRight: (a: A) => B) =>
(fa: Either<A, E>): B => (fa: Either<A, E>): B =>
fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right) fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right)

View File

@ -62,18 +62,18 @@ export const chain =
* @param onSome - Function to handle the Some case * @param onSome - Function to handle the Some case
* @returns A function that takes an Option and returns the folded value * @returns A function that takes an Option and returns the folded value
* @example * @example
* const result = fold( * const result = foldOption(
* () => 'No value', * () => 'No value',
* (value: number) => `Value: ${value}` * (value: number) => `Value: ${value}`
* )(some(42)) // Returns "Value: 42" * )(some(42)) // Returns "Value: 42"
* *
* @example * @example
* const result = fold( * const result = foldOption(
* () => 'No value', * () => 'No value',
* (value: number) => `Value: ${value}` * (value: number) => `Value: ${value}`
* )(none) // Returns "No value" * )(none) // Returns "No value"
*/ */
export const fold = export const foldOption =
<A, B>(onNone: () => B, onSome: (value: A) => B) => (option: Option<A>): B => <A, B>(onNone: () => B, onSome: (value: A) => B) => (option: Option<A>): B =>
option._tag === 'Some' ? onSome(option.value) : onNone() option._tag === 'Some' ? onSome(option.value) : onNone()
@ -84,19 +84,19 @@ export const fold =
* @param option - The Option to fold * @param option - The Option to fold
* @returns An object with methods to handle both cases * @returns An object with methods to handle both cases
* @example * @example
* some(42).fold({ * some(42).foldOptionC({
* onNone: () => 'No value', * onNone: () => 'No value',
* onSome: (value) => `Value: ${value}` * onSome: (value) => `Value: ${value}`
* }) // Returns "Value: 42" * }) // Returns "Value: 42"
*/ */
export const foldC = <A>(option: Option<A>) => ({ export const foldOptionC = <A>(option: Option<A>) => ({
/** /**
* @param handlers - Object containing both case handlers * @param handlers - Object containing both case handlers
* @param handlers.onNone - Function to handle None case * @param handlers.onNone - Function to handle None case
* @param handlers.onSome - Function to handle Some case * @param handlers.onSome - Function to handle Some case
* @returns The folded value * @returns The folded value
*/ */
fold: <B>(handlers: {onNone: () => B, onSome: (value: A) => B}): B => foldOption: <B>(handlers: {onNone: () => B, onSome: (value: A) => B}): B =>
option._tag === 'Some' option._tag === 'Some'
? handlers.onSome(option.value) ? handlers.onSome(option.value)
: handlers.onNone(), : handlers.onNone(),