-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridge.res
More file actions
63 lines (51 loc) · 1.64 KB
/
Copy pathBridge.res
File metadata and controls
63 lines (51 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: PMPL-1.0-or-later OR PMPL-1.0-or-later
// SPDX-FileCopyrightText: 2024 Hyperpolymath
/**
* Bridge - A minimal input → output transformation module.
* Demonstrates the core pattern: receive input, transform, emit output.
*/
/** Result type for bridge operations */
type bridgeResult<'a> = Ok('a) | Error(string)
/** Bridge configuration */
type config = {
name: string,
version: string,
}
/** Default configuration */
let defaultConfig: config = {
name: "bridge",
version: "0.1.0",
}
/** Transform input string to output with bridge metadata */
let transform = (input: string): string => {
`[bridge] ${input}`
}
/** Transform with result wrapper for error handling */
let transformSafe = (input: string): bridgeResult<string> => {
if input == "" {
Error("Input cannot be empty")
} else {
Ok(transform(input))
}
}
/** Compose two transformations */
let compose = (f: string => string, g: string => string): (string => string) => {
(input: string) => g(f(input))
}
/** Identity transform - returns input unchanged */
let identity = (input: string): string => input
/** Uppercase transform - binds to JavaScript String.toUpperCase */
@send external toUpperCase: string => string = "toUpperCase"
let uppercase = (input: string): string => input->toUpperCase
/** Prefix transform factory */
let prefix = (pre: string): (string => string) => {
(input: string) => `${pre}${input}`
}
/** Suffix transform factory */
let suffix = (suf: string): (string => string) => {
(input: string) => `${input}${suf}`
}
/** Get bridge info */
let info = (config: config): string => {
`${config.name} v${config.version}`
}