What is FSharp.Data.Adaptive and how does it work?
masterFSharp.Data.Adaptive is a library for handling changeable ("adaptive") data using functional principles. It allows you to treat adaptive values as if they were immutable data while maintaining efficient, incremental updates under the hood.
The library distinguishes between two types of container cells:
cval<'T>(Changeable cells): These are the source of truth that can be modified directly by user code. They are prefixed withcfor "changeable".aval<'T>(Adaptive cells): These represent dependent computations. They depend on changeable cells or other adaptive cells but cannot be modified directly. They are prefixed withafor "adaptive".
Adaptive cells are compatible with changeable cells via inheritance. To retrieve the current value from an adaptive cell and exit the "adaptive world," use AVal.force.
let changeable = cval 10
let dependent = changeable |> AVal.map (fun a -> 2 * a)
dependent |> AVal.force // => 20
transact (fun () -> changeable.Value <- 1)
dependent |> AVal.force // => 2