-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tagged): add @typed-f/tagged package (#2)
* init(package): add @typed-f/tagged package * refactor(tagged): rename and remove type parameters * feat(package): update packages to use @typed-f/tagged package
- Loading branch information
Showing
19 changed files
with
300 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ module.exports = { | |
'setoid', | ||
'matchable', | ||
'maybe', | ||
'tagged', | ||
], | ||
], | ||
'scope-empty': [ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
import { Fun } from '@typed-f/function'; | ||
import { Functor } from '@typed-f/functor'; | ||
import { Functor1, Functor2, Functor3, Functor4 } from '@typed-f/functor'; | ||
import * as T from '@typed-f/tagged'; | ||
|
||
export interface Applicative<T> extends Functor<T> { | ||
interface ApplicativeBuilder<UnitType, ApType> { | ||
unit: UnitType; | ||
/** | ||
* @desc | ||
* Retype `Functor` methods | ||
* alias of `unit` | ||
*/ | ||
of: UnitType; | ||
|
||
map<U>(f: Fun<[T], U>): Applicative<U>; | ||
lift<U>(f: Fun<[T], U>): Applicative<U>; | ||
fmap<U>(f: Fun<[T], U>): Applicative<U>; | ||
ap: ApType; | ||
} | ||
type AB<U, A> = ApplicativeBuilder<U, A>; | ||
|
||
/** | ||
* @desc | ||
* `Applicative` methods | ||
*/ | ||
type A1U<Tag extends keyof T.Tag1List<any>, A0> = Fun<[A0], T.Tag1List<A0>[Tag]>; | ||
type A2U<Tag extends keyof T.Tag2List<any, any>, A0, A1> = Fun<[A1], T.Tag2List<A0, A1>[Tag]>; | ||
type A3U<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> = Fun<[A2], T.Tag3List<A0, A1, A2>[Tag]>; | ||
type A4U<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> = Fun<[A3], T.Tag4List<A0, A1, A2, A3>[Tag]>; | ||
|
||
unit(arg: T): Applicative<T>; | ||
/** | ||
* @desc | ||
* alias of `unit` | ||
*/ | ||
of(arg: T): Applicative<T>; | ||
type A1A<Tag extends keyof T.Tag1List<any>, A0> = <R>(wf: T.Tag1List<Fun<[A0], R>>[Tag]) => T.Tag1List<R>[Tag]; | ||
type A2A<Tag extends keyof T.Tag2List<any, any>, A0, A1> = <R>(wf: T.Tag2List<A0, Fun<[A1], R>>[Tag]) => T.Tag2List<A0, R>[Tag]; | ||
type A3A<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> = <R>(wf: T.Tag3List<A0, A1, Fun<[A2], R>>[Tag]) => T.Tag3List<A0, A1, R>[Tag]; | ||
type A4A<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> = <R>(wf: T.Tag4List<A0, A1, A2, Fun<[A3], R>>[Tag]) => T.Tag4List<A0, A1, A2, R>[Tag]; | ||
|
||
ap<U>(wf: Applicative<Fun<[T], U>>): Applicative<U>; | ||
} | ||
export interface Applicative1<Tag extends keyof T.Tag1List<any>, A0> extends Functor1<Tag, A0>, AB<A1U<Tag, A0>, A1A<Tag, A0>> {} | ||
export interface Applicative2<Tag extends keyof T.Tag2List<any, any>, A0, A1> extends Functor2<Tag, A0, A1>, AB<A2U<Tag, A0, A1>, A2A<Tag, A0, A1>> {} | ||
export interface Applicative3<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> extends Functor3<Tag, A0, A1, A2>, AB<A3U<Tag, A0, A1, A2>, A3A<Tag, A0, A1, A2>> {} | ||
export interface Applicative4<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> extends Functor4<Tag, A0, A1, A2, A3>, AB<A4U<Tag, A0, A1, A2, A3>, A4A<Tag, A0, A1, A2, A3>> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import { Fun } from '@typed-f/function'; | ||
import * as T from '@typed-f/tagged'; | ||
|
||
export interface Functor<T> { | ||
/** | ||
* @desc | ||
* `Functor` methods | ||
*/ | ||
|
||
map<U>(f: Fun<[T], U>): Functor<U>; | ||
interface FunctorBuilder<MapType> { | ||
map: MapType; | ||
/** | ||
* @desc | ||
* alias of `map` | ||
*/ | ||
lift<U>(f: Fun<[T], U>): Functor<U>; | ||
lift: MapType; | ||
/** | ||
* @desc | ||
* alias of `map` | ||
*/ | ||
fmap<U>(f: Fun<[T], U>): Functor<U>; | ||
fmap: MapType; | ||
} | ||
type FB<M> = FunctorBuilder<M>; | ||
|
||
type F1M<Tag extends keyof T.Tag1List<any>, A0> = <R>( | ||
f: Fun<[A0], R>, | ||
) => T.Tag1List<R>[Tag]; | ||
type F2M<Tag extends keyof T.Tag2List<any, any>, A0, A1> = <R>( | ||
f: Fun<[A1], R>, | ||
) => T.Tag2List<A0, R>[Tag]; | ||
type F3M<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> = <R>( | ||
f: Fun<[A2], R>, | ||
) => T.Tag3List<A0, A1, R>[Tag]; | ||
type F4M<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> = <R>( | ||
f: Fun<[A3], R>, | ||
) => T.Tag4List<A0, A1, A2, R>[Tag]; | ||
|
||
export interface Functor1<Tag extends keyof T.Tag1List<any>, A0> extends T.Tagged<Tag>, FB<F1M<Tag, A0>> {} | ||
export interface Functor2<Tag extends keyof T.Tag2List<any, any>, A0, A1> extends T.Tagged<Tag>, FB<F2M<Tag, A0, A1>> {} | ||
export interface Functor3<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> extends T.Tagged<Tag>, FB<F3M<Tag, A0, A1, A2>> {} | ||
export interface Functor4<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> extends T.Tagged<Tag>, FB<F4M<Tag, A0, A1, A2, A3>> {} | ||
|
||
export namespace Functor { | ||
export function map<T, U>(f: Fun<[T], U>): <Tag extends keyof T.Tag1List<any>>( | ||
wa: Functor1<Tag, T>, | ||
) => T.Tag1List<U>[Tag] { | ||
return function (wa) { | ||
if ('map' in wa) { | ||
return (wa as any).map(f); | ||
} | ||
|
||
throw new Error('Parameter is not a functor. You cannot call the function map with non-functor.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,23 @@ | ||
import { Applicative } from '@typed-f/applicative'; | ||
import { Applicative1, Applicative2, Applicative3, Applicative4 } from '@typed-f/applicative'; | ||
import { Fun } from '@typed-f/function'; | ||
import * as T from '@typed-f/tagged'; | ||
|
||
export interface Monad<T> extends Applicative<T> { | ||
/** | ||
* @desc | ||
* Retype `Functor` methods | ||
*/ | ||
|
||
map<U>(f: Fun<[T], U>): Monad<U>; | ||
lift<U>(f: Fun<[T], U>): Monad<U>; | ||
fmap<U>(f: Fun<[T], U>): Monad<U>; | ||
|
||
/** | ||
* @desc | ||
* Retype `Functor` methods | ||
*/ | ||
|
||
unit(arg: T): Monad<T>; | ||
of(arg: T): Monad<T>; | ||
|
||
ap<U>(wf: Monad<Fun<[T], U>>): Monad<U>; | ||
|
||
/** | ||
* @desc | ||
* `Monad` methods | ||
*/ | ||
|
||
bind<U>(wf: Fun<[T], Monad<U>>): Monad<U>; | ||
interface MonadBuilder<BindType> { | ||
bind: BindType; | ||
/** | ||
* @desc | ||
* alias of `bind` | ||
*/ | ||
chain<U>(wf: Fun<[T], Monad<U>>): Monad<U>; | ||
chain: BindType; | ||
} | ||
type MB<B> = MonadBuilder<B>; | ||
|
||
type M1B<Tag extends keyof T.Tag1List<any>, A0> = <R>(wf: Fun<[A0], T.Tag1List<R>[Tag]>) => T.Tag1List<R>[Tag]; | ||
type M2B<Tag extends keyof T.Tag2List<any, any>, A0, A1> = <R>(wf: Fun<[A1], T.Tag2List<A0, R>[Tag]>) => T.Tag2List<A0, R>[Tag]; | ||
type M3B<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> = <R>(wf: Fun<[A2], T.Tag3List<A0, A1, R>[Tag]>) => T.Tag3List<A0, A1, R>[Tag]; | ||
type M4B<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> = <R>(wf: Fun<[A3], T.Tag4List<A0, A1, A2, R>[Tag]>) => T.Tag4List<A0, A1, A2, R>[Tag]; | ||
|
||
export interface Monad1<Tag extends keyof T.Tag1List<any>, A0> extends Applicative1<Tag, A0>, MB<M1B<Tag, A0>> {} | ||
export interface Monad2<Tag extends keyof T.Tag2List<any, any>, A0, A1> extends Applicative2<Tag, A0, A1>, MB<M2B<Tag, A0, A1>> {} | ||
export interface Monad3<Tag extends keyof T.Tag3List<any, any, any>, A0, A1, A2> extends Applicative3<Tag, A0, A1, A2>, MB<M3B<Tag, A0, A1, A2>> {} | ||
export interface Monad4<Tag extends keyof T.Tag4List<any, any, any, any>, A0, A1, A2, A3> extends Applicative4<Tag, A0, A1, A2, A3>, MB<M4B<Tag, A0, A1, A2, A3>> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.