diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-03-02 11:24:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-03-02 11:24:21 +0000 |
| commit | a715084a95b3ee6de1d73bab5ec1078f9308e6e3 (patch) | |
| tree | efbb6f1bfb7c556144106e03e0e49b161eeb9adf /examples | |
| parent | 41b5979b3397b3bdc210e7baf768e6824ff752a5 (diff) | |
Add example for generic functions
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/32-generic-functions/shed.toml | 7 | ||||
| -rw-r--r-- | examples/32-generic-functions/src/HelloWorld.shed | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/examples/32-generic-functions/shed.toml b/examples/32-generic-functions/shed.toml new file mode 100644 index 00000000..9c1a6d01 --- /dev/null +++ b/examples/32-generic-functions/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world!" diff --git a/examples/32-generic-functions/src/HelloWorld.shed b/examples/32-generic-functions/src/HelloWorld.shed new file mode 100644 index 00000000..bc7b1243 --- /dev/null +++ b/examples/32-generic-functions/src/HelloWorld.shed @@ -0,0 +1,15 @@ +pub fun main() ! Io -> Unit { + val message = compose( + fn (a: String) { a + ", " }, + fn (b: String) { b + "world!\n" }, + )("hello"); + print!(message); +} + +fun compose[A, B, C]( + f: fn (A) -> B, + g: fn (B) -> C +) -> fn (A) -> C { + return fn (a) { g(f(a)) }; +} + |
