Skip to content

Commit 48fc603

Browse files
hyperpolymathclaude
andcommitted
feat(stdlib): implement compose/flip/pipe in Core.as, fix Display for Int
Core.as: Added compose (function composition), flip (argument order reversal), and pipe (function application) — lambda syntax works now. traits.as: Display for Int now delegates to int_to_string builtin instead of returning placeholder "int". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9c98905 commit 48fc603

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

stdlib/Core.as

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ pub fn const[A, B](x: A, own y: B) -> A {
1515
return x;
1616
}
1717

18-
// TODO: Function composition and flip require lambda syntax
19-
// which is not yet fully supported by the parser
18+
/// Function composition: (f >> g)(x) = g(f(x))
19+
pub fn compose[A, B, C](f: A -> B, g: B -> C) -> (A -> C) {
20+
return fn(x: A) -> C { g(f(x)) };
21+
}
22+
23+
/// Flip argument order: flip(f)(a, b) = f(b, a)
24+
pub fn flip[A, B, C](f: (A, B) -> C) -> ((B, A) -> C) {
25+
return fn(b: B, a: A) -> C { f(a, b) };
26+
}
27+
28+
/// Apply a function to a value (pipe operator)
29+
pub fn pipe[A, B](x: A, f: A -> B) -> B {
30+
return f(x);
31+
}
2032

2133
// Comparison operators
2234

stdlib/traits.as

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ impl Hash for Int {
157157

158158
impl Display for Int {
159159
pub fn to_string(ref self) -> String {
160-
// TODO: Implement actual int-to-string conversion
161-
return "int";
160+
return int_to_string(*self);
162161
}
163162
}
164163

0 commit comments

Comments
 (0)