Created
June 7, 2024 05:50
-
-
Save galanggg/49a1adbee3b08490c7079781f7657bb1 to your computer and use it in GitHub Desktop.
Revisions
-
galanggg created this gist
Jun 7, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ //define type for increment function type Increment = (x: number) => number const increment: Increment = x => x + 1 //define type for toString function type Tostring = (x: number) => string const toString: Tostring = x => `"${x}"` //define type for increment then to string function type IncrementThenToString = (x: number) => string const increment_then_tostring: IncrementThenToString = x => toString(increment(x)) console.log(increment_then_tostring(6)) //make Compose Function type Compose = <A,B,C> { f: (x: B) => C, g: (x: A) => B => (x: A) => C } const compose: Compose = (f,g) => x => f(g(x)) const increment_then_tostring2: IncrementThenToString = compose(tostring, increment) console.log(increment_then_tostring2(6))