F# core

fukurou

the supreme coder
ADMIN
the F stands 4 fuck
Code:
module AbsDictionaryDB

open System.Collections.Generic

type DictionaryDB(saveFunc, loadFunc) =
    let db = Dictionary<string, string>()

    member _.Save key value = saveFunc db key value
    member _.Load key = loadFunc db key

// Example save/load logic
let defaultSave (db: Dictionary<string, string>) key value =
    db.[key] <- value
    printfn "Default Save: Key = %s, Value = %s" key value

let defaultLoad (db: Dictionary<string, string>) key =
    if db.ContainsKey(key) then
        printfn "Default Load: Key = %s, Value = %s" key db.[key]
        db.[key]
    else
        printfn "Key not found: %s" key
        ""

// Custom save/load logic for a new instance
let customSave (db: Dictionary<string, string>) key value =
    db.[key] <- value
    printfn "Custom Save: Key = %s (custom logic applied!)" key

let customLoad (db: Dictionary<string, string>) key =
    if db.ContainsKey(key) then
        printfn "Custom Load: Key = %s, Value = %s (custom logic applied!)" key db.[key]
        db.[key]
    else
        printfn "Key not found (custom logic): %s" key
        ""

// Create instances with different logic
let defaultDb = DictionaryDB(defaultSave, defaultLoad)
let customDb = DictionaryDB(customSave, customLoad)

// Use the instances
defaultDb.Save "Hello" "World"
defaultDb.Load "Hello"

customDb.Save "CustomKey" "CustomValue"
customDb.Load "CustomKey"
 
Top