A code generation library for Gleam
2

Configure Feed

Select the types of activity you want to include in your feed.

Implement unary operators

Gears (Sep 30, 2025, 5:28 PM +0100) cd25eac5 1dd29ef7

+35
+27
src/trick.gleam
··· 201 201 ) -> Expression(Float) { 202 202 binary_operator(left, ">=.", right) 203 203 } 204 + 205 + fn unary_operator(operator: String, value: Expression(a)) -> Expression(a) { 206 + [doc.from_string(operator), value.document] |> doc.concat |> Expression 207 + } 208 + 209 + pub fn negate_int(value: Expression(Int)) -> Expression(Int) { 210 + unary_operator("-", value) 211 + } 212 + 213 + pub fn negate_bool(value: Expression(Bool)) -> Expression(Bool) { 214 + unary_operator("!", value) 215 + } 216 + // TODO: 217 + // BitString 218 + // Block 219 + // Call 220 + // Case 221 + // Echo 222 + // FieldAccess 223 + // Float 224 + // Fn 225 + // FnCapture 226 + // Pipes 227 + // RecordUpdate 228 + // Tuple 229 + // TupleIndex 230 + // Variable
+8
test/trick_test.gleam
··· 130 130 |> trick.expression_to_string 131 131 == "False != False" 132 132 } 133 + 134 + pub fn unary_operator_test() { 135 + assert 10 |> trick.int |> trick.negate_int |> trick.expression_to_string 136 + == "-10" 137 + 138 + assert False |> trick.bool |> trick.negate_bool |> trick.expression_to_string 139 + == "!False" 140 + }