-
Notifications
You must be signed in to change notification settings - Fork 0
ValueObject
Ben Christel edited this page Dec 21, 2020
·
1 revision
A Value Object is a Value whose Limbs are pure Functions.
A FunctionClosure is the "base case" value object.
Value objects are useful for computing a set of values lazily, or creating partially applied functions.
Example:
function Path(components) {
return {
forUnix: cache(forUnix),
forWindows: cache(forWindows),
}
function forUnix() {
return components.join("/")
}
function forWindows() {
return components.join("\\")
}
}
Annotated with Capabilities:
declare cache[func]<T>([func]() => T): [func]() => T
function Path[func](components) {
return {
forUnix: cache(forUnix),
forWindows: cache(forWindows),
}
function forUnix[func]() {
return components.join("/")
}
function forWindows[func]() {
return components.join("\\")
}
}
Not complicated—everything here is a pure function.