diff --git a/package.json b/package.json index fcaaf2e..4ab7b9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fp-lib", - "version": "1.0.3", + "version": "1.0.4", "description": "Zero-dependency functional programming library optimized for Bun", "main": "dist/index.js", "module": "dist/index.js", diff --git a/src/either.ts b/src/either.ts index 67d0355..1b17ce9 100644 --- a/src/either.ts +++ b/src/either.ts @@ -74,7 +74,7 @@ export const eitherChain = * @param onRight - Function to handle Right case * @returns A function that takes an Either and returns the folded value */ -export const fold = +export const foldEither = (onLeft: (e: E) => B, onRight: (a: A) => B) => (fa: Either): B => fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right) diff --git a/src/option.ts b/src/option.ts index 12f6836..6499929 100644 --- a/src/option.ts +++ b/src/option.ts @@ -62,18 +62,18 @@ export const chain = * @param onSome - Function to handle the Some case * @returns A function that takes an Option and returns the folded value * @example - * const result = fold( + * const result = foldOption( * () => 'No value', * (value: number) => `Value: ${value}` * )(some(42)) // Returns "Value: 42" * * @example - * const result = fold( + * const result = foldOption( * () => 'No value', * (value: number) => `Value: ${value}` * )(none) // Returns "No value" */ -export const fold = +export const foldOption = (onNone: () => B, onSome: (value: A) => B) => (option: Option): B => option._tag === 'Some' ? onSome(option.value) : onNone() @@ -84,19 +84,19 @@ export const fold = * @param option - The Option to fold * @returns An object with methods to handle both cases * @example - * some(42).fold({ + * some(42).foldOptionC({ * onNone: () => 'No value', * onSome: (value) => `Value: ${value}` * }) // Returns "Value: 42" */ -export const foldC = (option: Option) => ({ +export const foldOptionC = (option: Option) => ({ /** * @param handlers - Object containing both case handlers * @param handlers.onNone - Function to handle None case * @param handlers.onSome - Function to handle Some case * @returns The folded value */ - fold: (handlers: {onNone: () => B, onSome: (value: A) => B}): B => + foldOption: (handlers: {onNone: () => B, onSome: (value: A) => B}): B => option._tag === 'Some' ? handlers.onSome(option.value) : handlers.onNone(),