Compare commits

...

2 Commits

Author SHA1 Message Date
e220b7930c Add Tag type and hasTag function 2025-05-29 11:39:33 -05:00
b53558e2d1 Reorder type generic order 2025-05-29 11:38:50 -05:00
2 changed files with 7 additions and 1 deletions

View File

@ -22,7 +22,7 @@ export const eitherChain =
fa._tag === 'Right' ? f(fa.right) : fa
export const fold =
<A, B, E>(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._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right)

View File

@ -174,5 +174,11 @@ export const tryCatch = <A>(f: () => A): Either<A, Error> => {
}
}
export interface Tag<T> {
readonly _tag: T
}
export const hasTag = (x: string) => (y: Tag<string>) => x === y._tag
export const fromNullable = <A>(a: A | null | undefined): Option<A> =>
a == null ? none : some(a)