Fix exports for fold
This commit is contained in:
parent
b71d39c845
commit
6f55c892c2
@ -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",
|
||||
|
||||
@ -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 =
|
||||
<A, E, B>(onLeft: (e: E) => B, onRight: (a: A) => B) =>
|
||||
(fa: Either<A, E>): B =>
|
||||
fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right)
|
||||
|
||||
@ -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 =
|
||||
<A, B>(onNone: () => B, onSome: (value: A) => B) => (option: Option<A>): 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 = <A>(option: Option<A>) => ({
|
||||
export const foldOptionC = <A>(option: Option<A>) => ({
|
||||
/**
|
||||
* @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: <B>(handlers: {onNone: () => B, onSome: (value: A) => B}): B =>
|
||||
foldOption: <B>(handlers: {onNone: () => B, onSome: (value: A) => B}): B =>
|
||||
option._tag === 'Some'
|
||||
? handlers.onSome(option.value)
|
||||
: handlers.onNone(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user