AVal Module
Core operations for creating and transforming adaptive values. Adaptive values automatically track dependencies and recompute only when their inputs change.
Mibo.Adaptive provides incremental computation with a pull-evaluate model. A write bumps the version of its source and the write generation of its graph. A read version-checks its dependencies and recomputes only when one moved; the write-generation cache keeps repeated reads at the same generation O(1) per node.
Performance Guidance:
Use map ,map2 for 1-2 dependencies (most common case)Use mapN ,reduce ,sum for N dependencies (avoids O(N) node chains)
Example
Basic usage:
let x = CVal.create 1
let y = CVal.create 2
let sum = AVal.map2 (+) (CVal.value x) (CVal.value y)
printfn "%d" (AVal.getValue sum) // 3
x.Set(10)
printfn "%d" (AVal.getValue sum) // 12
Types
| Type | Description |
|
An adaptive value whose content is supplied by an external snapshot
function, re-read only when invalidated via the handle returned by
AVal.ofExternal (FDA |
Functions and values
| Function or value |
Description
|
|
|
|
Adaptively applies the mapping to the two values and adaptively depends
on the adaptive value the mapping returns (FDA
|
|
|
|
|
Full Usage:
constant value
Parameters:
'T
-
The constant value.
Returns: aval<'T>
An adaptive value that always returns the given value.
Modifiers: inline Type parameters: 'T |
Creates a constant adaptive value that never changes. Constant values have zero overhead - they never recompute and don't track dependencies. Use this for values that are known at creation time and will never change.
Example
val pi: obj
val doubled: obj
|
Full Usage:
custom compute
Parameters:
unit -> 'T
Returns: aval<'T>
Modifiers: inline Type parameters: 'T |
Creates a custom adaptive value using the given computation (FDA
|
Full Usage:
delay create
Parameters:
unit -> 'T
Returns: aval<'T>
Modifiers: inline Type parameters: 'T |
Creates a constant adaptive value using the given create function (FDA
Example
val v: obj
|
Full Usage:
force value
Parameters:
aval<'T>
Returns: 'T
Modifiers: inline Type parameters: 'T |
Evaluates the given adaptive value and returns its current value (FDA
|
Full Usage:
getValue value
Parameters:
aval<'T>
Returns: 'T
Modifiers: inline Type parameters: 'T |
|
|
|
|
|
Full Usage:
init value
Parameters:
'T
Returns: cval<'T>
Modifiers: inline Type parameters: 'T |
Creates a changeable value initially holding the given value (FDA
|
|
Transforms an adaptive value using a mapping function. The function is called lazily - only when the result is read and the source has changed. The result is cached until the source changes.
Example
val celsius: obj
val fahrenheit: obj
|
Full Usage:
map2 f left right
Parameters:
'T -> 'U -> 'V
-
The function to combine the two values.
left : aval<'T>
-
The first adaptive value.
right : aval<'U>
-
The second adaptive value.
Returns: aval<'V>
A new adaptive value that combines both inputs.
Modifiers: inline Type parameters: 'T, 'U, 'V |
Combines two adaptive values using a mapping function. Recomputes only when either input changes. Both inputs are read in a single evaluation.
Example
val width: obj
val height: obj
val area: obj
|
Full Usage:
map3 f a b c
Parameters:
'A -> 'B -> 'C -> 'T
-
The function to combine the three values.
a : aval<'A>
-
The first adaptive value.
b : aval<'B>
-
The second adaptive value.
c : aval<'C>
-
The third adaptive value.
Returns: aval<'T>
A new adaptive value that combines all three inputs.
Modifiers: inline Type parameters: 'A, 'B, 'C, 'T |
Combines three adaptive values using a mapping function. Recomputes only when one of the three inputs changes.
Example
val r: obj
val g: obj
val b: obj
val color: obj
val sprintf: format: Printf.StringFormat<'T> -> 'T
|
Full Usage:
map4 f a b c d
Parameters:
'A -> 'B -> 'C -> 'D -> 'T
-
The function to combine the four values.
a : aval<'A>
-
The first adaptive value.
b : aval<'B>
-
The second adaptive value.
c : aval<'C>
-
The third adaptive value.
d : aval<'D>
-
The fourth adaptive value.
Returns: aval<'T>
A new adaptive value that combines all four inputs.
Modifiers: inline Type parameters: 'A, 'B, 'C, 'D, 'T |
Combines four adaptive values using a mapping function. Recomputes only when one of the four inputs changes.
Example
val x: obj
val y: obj
val width: obj
val height: obj
val rect: obj
|
Full Usage:
mapN compute deps
Parameters:
'T[] -> 'U
-
A function that receives an array of all current values and produces the result.
deps : aval<'T>[]
-
An array of adaptive values to combine.
Returns: aval<'U>
A new adaptive value that combines all inputs.
Modifiers: inline Type parameters: 'T, 'U |
Combines N adaptive values of the same type using a function that receives all values as an array. Optimized for wide fan-in patterns where many inputs feed into a single computation.
When to use: Use Performance: Uses a single node instead of O(N) nodes from chained Note: The array passed to the compute function is reused by the node and is valid only during the call. Do not retain it. If you only need a reduction (sum, min, max, etc.), prefer reduce for better performance.
Example
val sensors: obj array
module Array
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val i: int
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val deps: obj array
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val s: obj
val average: obj
val average: array: 'T array -> 'T (requires member (+) and member DivideByInt and member Zero)
|
|
|
|
|
|
|
|
|
Full Usage:
ofExternal read
Parameters:
unit -> 'T
Returns: aval<'T> * (unit -> unit)
Modifiers: inline Type parameters: 'T (requires equality) |
Creates an adaptive value from an external snapshot function and an
invalidate handle (FDA
Example
val mutable current: int
val value: obj
val invalidate: (unit -> obj)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
Full Usage:
reduce init reduce deps
Parameters:
'T
-
The initial/identity value for the reduction (e.g., 0 for sum, 1 for product).
reduce : 'T -> 'T -> 'T
-
A binary function to combine values (must be associative for correct results).
deps : aval<'T>[]
-
An array of adaptive values to reduce.
Returns: aval<'T>
A new adaptive value containing the reduction result.
Modifiers: inline Type parameters: 'T |
Reduces N adaptive values using a binary operation and initial value. Optimized for wide fan-in aggregation patterns (sum, product, min, max, etc.).
When to use: Use Performance: More efficient than Empty array behavior: Returns the init value when deps is empty.
Example
val prices: obj array
val deps: obj array
module Array
from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val p: obj
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val total: obj
val product: obj
val maxPrice: obj
namespace System
type Double =
member CompareTo: value: float -> int + 1 overload
member Equals: obj: float -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 3 overloads
member TryFormat: utf8Destination: Span<byte> * bytesWritten: byref<int> * ?format: ReadOnlySpan<char> * ?provider: IFormatProvider -> bool + 1 overload
static member (<) : left: float * right: float -> bool
static member (<=) : left: float * right: float -> bool
static member (<>) : left: float * right: float -> bool
static member (=) : left: float * right: float -> bool
...
<summary>Represents a double-precision floating-point number.</summary> field float.MinValue: float = -1.79769313486e+308
val max: e1: 'T -> e2: 'T -> 'T (requires comparison)
|
Sums N adaptive integer values. Convenience function equivalent to
Performance: Uses a single node instead of O(N) nodes from chained additions. Provides 3-100× speedup for summing many values (10-500 inputs). Empty array behavior: Returns 0 when deps is empty.
Example
val scores: obj array
val deps: obj array
module Array
from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val s: obj
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val totalScore: obj
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool member IsProperSubsetOf: otherSet: Set<'T> -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
Mibo