4 people like it.

Foundation functions

F# utility functions for Option, Result, and others. Adapted to .NET 6.0

  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: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
 70: 
 71: 
 72: 
 73: 
 74: 
 75: 
 76: 
 77: 
 78: 
 79: 
 80: 
 81: 
 82: 
 83: 
 84: 
 85: 
 86: 
 87: 
 88: 
 89: 
 90: 
 91: 
 92: 
 93: 
 94: 
 95: 
 96: 
 97: 
 98: 
 99: 
100: 
101: 
102: 
103: 
104: 
105: 
106: 
107: 
108: 
109: 
110: 
111: 
112: 
113: 
114: 
115: 
116: 
117: 
118: 
119: 
120: 
121: 
122: 
123: 
124: 
125: 
126: 
127: 
128: 
129: 
130: 
131: 
132: 
133: 
134: 
135: 
136: 
137: 
138: 
139: 
140: 
141: 
142: 
143: 
144: 
145: 
146: 
147: 
148: 
149: 
150: 
151: 
152: 
153: 
154: 
155: 
156: 
157: 
158: 
159: 
160: 
161: 
162: 
163: 
164: 
165: 
166: 
167: 
168: 
169: 
170: 
171: 
172: 
173: 
174: 
175: 
176: 
177: 
178: 
179: 
180: 
181: 
182: 
183: 
184: 
185: 
186: 
187: 
188: 
189: 
190: 
191: 
192: 
193: 
194: 
195: 
196: 
197: 
198: 
199: 
200: 
201: 
202: 
203: 
204: 
205: 
206: 
// v8
module TiraxTech.Foundation

open System.Threading.Tasks

let inline sideEffect ([<InlineIfLambda>] f) x = (f x); x

let inline flip f a b = f b a
let inline constant x = fun _ -> x

let inline cast<'t> (x :obj) = x :?> 't
let inline tryCast<'a> (x:obj) =
    match x with
    | :? 'a as s -> Some s
    | _ -> None

type System.Object with
  member inline o.cast<'T>() = o |> cast<'T>
  member inline o.tryCast<'T>() = o |> tryCast<'T>

module Itor =
  open System.Collections.Generic
  let fold :('b -> 'a -> 'b) -> 'b -> IEnumerator<'a> -> 'b = fun reducer init itor ->
    if itor.MoveNext() then
      let mutable v = init
      while itor.MoveNext() do
        v <- reducer v itor.Current
      v
    else
      init

module Seq =
  open System.Collections.Generic
  let fromIterator :IEnumerator<'a> -> 'a seq = fun itor ->
    seq {
      while itor.MoveNext() do
        yield itor.Current
    }

  let tryMin :'a seq -> 'a option = fun ss ->
    let itor = ss.GetEnumerator()
    if itor.MoveNext() then
      Some (itor |> Itor.fold min itor.Current)
    else
      None
  let tryMax :'a seq -> 'a option = fun s ->
    let itor = s.GetEnumerator()
    if itor.MoveNext() then
      Some (itor |> Itor.fold max itor.Current)
    else
      None

module Option =
  let inline then' ([<InlineIfLambda>] fsome) ([<InlineIfLambda>] fnone) = function
  | Some x -> fsome x
  | None -> fnone()

  let inline filter ([<InlineIfLambda>] predicate) = then' (fun v -> if predicate v then Some v else None) (constant None)
  
  let inline getOrDefault def = function
  | Some x -> x
  | None -> def
    
  let inline getOrElse ([<InlineIfLambda>] def) = function
  | Some x -> x
  | None -> def()

  let join = function
  | None -> None
  | Some x -> x

  let inline do' ([<InlineIfLambda>] fsome) = then' fsome id
  let inline orTry ([<InlineIfLambda>] fnone: unit -> 'a option) = function
  | None -> fnone()
  | x -> x

  let inline ap other = function
  | None -> None
  | Some f -> other |> Option.map f

  let inline call x = function
  | None -> None
  | Some f -> Some (f x)
    
  let inline mapTask (f: 'a -> Task<'b>) = function
  | Some x -> task {
                let! result = f x
                return Some result
              }
  | None -> Task.FromResult None
    
  let inline bindTask ([<InlineIfLambda>] f: 'a -> Task<'b option>) = function
  | Some x -> f x
  | None -> Task.FromResult None
    
  let inline mapAsync (f: 'a -> Async<'b>) = function
  | Some x -> async {
                let! result = f x
                return Some result
              }
  | None -> async { return None }
    
  let inline bindAsync ([<InlineIfLambda>] f: 'a -> Async<'b option>) = function
  | Some x -> f x
  | None -> async { return None }


open System.Runtime.CompilerServices
[<Extension>]
type OptionExtension =
  [<Extension>] static member inline ap(x: Option<'a -> 'b>, other) = x |> Option.ap other
  [<Extension>] static member inline call(x: Option<'a -> 'b>, p) = x |> Option.call p
  [<Extension>] static member inline join(x: 'a option option) = x |> Option.join
  
type Option<'a> with
  member inline x.do'([<InlineIfLambda>] fsome) = x |> Option.do' fsome
  member inline x.then' ([<InlineIfLambda>] fsome) ([<InlineIfLambda>] fnone) = x |> Option.then' fsome fnone
  member inline x.filter([<InlineIfLambda>] predicate) = x |> Option.filter predicate
  member inline x.get() = Option.get x
  member inline x.getOrDefault(def) = x |> Option.getOrDefault def
  member inline x.getOrElse([<InlineIfLambda>] f) = x |> Option.getOrElse f
  member inline x.orTry([<InlineIfLambda>] fnone) = x |> Option.orTry fnone
  member inline x.defaultWith ([<InlineIfLambda>] v) = x |> Option.defaultWith v
  member inline x.bind ([<InlineIfLambda>] y) = x |> Option.bind y
  member inline x.map ([<InlineIfLambda>] f) = x |> Option.map f
  member inline x.mapTask ([<InlineIfLambda>] f) = x |> Option.mapTask f
  member inline x.bindTask ([<InlineIfLambda>] f) = x |> Option.bindTask f
  member inline x.mapAsync ([<InlineIfLambda>] f) = x |> Option.mapAsync f
  member inline x.bindAsync ([<InlineIfLambda>] f) = x |> Option.bindAsync f
  
module Result =
  let inline get ([<InlineIfLambda>] right) ([<InlineIfLambda>] wrong) = function
  | Ok y -> right y
  | Error x -> wrong x
    
  let inline mapAll ([<InlineIfLambda>] fright) ([<InlineIfLambda>] fwrong) = get (Ok << fright) (Error << fwrong)
  let inline ap other ([<InlineIfLambda>] fwrong) = get (fun f -> other |> Result.map f) (Error << fwrong)
  let inline isError x = x |> get (constant false) (constant true)
  let inline isOk x = x |> get (constant true) (constant false)
  let inline join r = r |> get id Error
  let inline bindAll ([<InlineIfLambda>] f: 'a -> Result<'c,'d>) ([<InlineIfLambda>] fwrong: 'b -> Result<'c,'d>) = get f fwrong
  let inline getOrDefault def = get id (constant def)
  let inline getOrElse ([<InlineIfLambda>] def) = get id def
  
  let inline mapTask ([<InlineIfLambda>] f: 'a -> Task<'c>) ([<InlineIfLambda>] fwrong: 'b -> 'd) = function
  | Ok x -> task {
              let! result = f x
              return Ok result
            }
  | Error y -> Task.FromResult <| Error (fwrong y)

  let inline bindTask ([<InlineIfLambda>] f: 'a -> Task<Result<'c,'d>>) ([<InlineIfLambda>] fwrong: 'b -> 'd) = function
  | Ok x -> f x
  | Error y -> Task.FromResult <| Error (fwrong y)
  
  let inline mapAsync ([<InlineIfLambda>] f: 'a -> Async<'c>) ([<InlineIfLambda>] fwrong: 'b -> 'd) = function
  | Ok x -> async {
              let! result = f x
              return Ok result
            }
  | Error y -> async { return Error (fwrong y) }

  let inline bindAsync ([<InlineIfLambda>] f: 'a -> Async<Result<'c,'d>>) ([<InlineIfLambda>] fwrong: 'b -> 'd) = function
  | Ok x -> f x
  | Error y -> async { return Error (fwrong y) }


type ResultBuilder() =
  member inline _.Bind(x: Result<'a,'b>, f: 'a -> Result<'c,'b>) = Result.bind f x
  member inline _.Return(v: 'c) = Ok v 
  member inline _.ReturnFrom(v: Result<'a,'b>) = v
  member inline _.Using(v: 'a, f: 'a -> Result<'b,'c>) :Result<'b,'c> = f v
  member inline _.Delay(f: unit -> Result<'a,'b>) = f
  member inline _.Run(f: unit -> Result<'a,'b>) = f()
  member inline _.TryWith(f: unit -> Result<'a,'b>, catch: exn -> Result<'a,'b>) = 
    try
      f()
    with
    | e -> catch e

let result = ResultBuilder()


// from http://stackoverflow.com/questions/3363184/f-how-to-elegantly-select-and-group-discriminated-unions/11798829#11798829
// let isUnionCase (c : Expr<_ -> 'T>)  = 
//   match c with
//   | Lambda (_, NewUnionCase(uci, _)) ->
//       let tagReader = Microsoft.FSharp.Reflection.FSharpValue.PreComputeUnionTagReader(uci.DeclaringType)
//       fun (v : 'T) -> (tagReader v) = uci.Tag
//   | _ -> failwith "Invalid expression"

/// memoizeWithKey: ('input -> 'key) -> ('input -> 'output) -> ('input -> 'output)
let memoizeWithKey (keyGetter: 'input -> 'key) (f: 'input -> 'output) =
  let dict = System.Collections.Concurrent.ConcurrentDictionary<'key,'output>()

  let memoizedFunc input =
    let key = keyGetter input
    match dict.TryGetValue key with
    | true, x -> x
    | false, _ ->
      let answer = f input
      dict.TryAdd(key, answer) |> ignore
      answer
  memoizedFunc

let memoize (f: 'a -> 'b) = memoizeWithKey id f
namespace TiraxTech
module Foundation

from TiraxTech
namespace System
namespace System.Threading
namespace System.Threading.Tasks
val sideEffect : f:('a -> unit) -> x:'a -> 'a
val f : ('a -> unit)
val x : 'a
val flip : f:('a -> 'b -> 'c) -> a:'b -> b:'a -> 'c
val f : ('a -> 'b -> 'c)
val a : 'b
val b : 'a
val constant : x:'a -> 'b -> 'a
val cast : x:obj -> 't
val x : obj
type obj = System.Object
val tryCast : x:obj -> 'a option
val s : 'a
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Multiple items
type Object =
  new : unit -> obj
  member Equals : obj:obj -> bool
  member GetHashCode : unit -> int
  member GetType : unit -> Type
  member ToString : unit -> string
  static member Equals : objA:obj * objB:obj -> bool
  static member ReferenceEquals : objA:obj * objB:obj -> bool

--------------------
System.Object() : System.Object
val o : System.Object
namespace System.Collections
namespace System.Collections.Generic
val fold : reducer:('b -> 'a -> 'b) -> init:'b -> itor:IEnumerator<'a> -> 'b
type IEnumerator<'T> =
  inherit IDisposable
  inherit IEnumerator
  member Current : 'T
val reducer : ('b -> 'a -> 'b)
val init : 'b
val itor : IEnumerator<'a>
System.Collections.IEnumerator.MoveNext() : bool
val mutable v : 'b
property IEnumerator.Current: 'a with get
module Seq

from Microsoft.FSharp.Collections
val fromIterator : itor:IEnumerator<'a> -> seq<'a>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

--------------------
type seq<'T> = IEnumerable<'T>
val tryMin : ss:seq<'a> -> 'a option (requires comparison)
type 'T option = Option<'T>
val ss : seq<'a> (requires comparison)
val itor : IEnumerator<'a> (requires comparison)
IEnumerable.GetEnumerator() : IEnumerator<'a>
module Itor

from TiraxTech.Foundation
val min : e1:'T -> e2:'T -> 'T (requires comparison)
val tryMax : s:seq<'a> -> 'a option (requires comparison)
val s : seq<'a> (requires comparison)
val max : e1:'T -> e2:'T -> 'T (requires comparison)
module Option

from Microsoft.FSharp.Core
val then' : fsome:('a -> 'b) -> fnone:(unit -> 'b) -> _arg1:'a option -> 'b
val fsome : ('a -> 'b)
val fnone : (unit -> 'b)
val filter : predicate:('a -> bool) -> ('a option -> 'a option)
val predicate : ('a -> bool)
val v : 'a
val getOrDefault : def:'a -> _arg1:'a option -> 'a
val def : 'a
val getOrElse : def:(unit -> 'a) -> _arg1:'a option -> 'a
val def : (unit -> 'a)
val join : _arg1:'a option option -> 'a option
val x : 'a option
val do' : fsome:('a -> unit) -> ('a option -> unit)
val fsome : ('a -> unit)
val id : x:'T -> 'T
val orTry : fnone:(unit -> 'a option) -> _arg1:'a option -> 'a option
val fnone : (unit -> 'a option)
type unit = Unit
val ap : other:'a option -> _arg1:('a -> 'b) option -> 'b option
val other : 'a option
val f : ('a -> 'b)
val map : mapping:('T -> 'U) -> option:'T option -> 'U option
val call : x:'a -> _arg1:('a -> 'b) option -> 'b option
val mapTask : f:('a -> Task<'b>) -> _arg1:'a0 option -> Task<'b1 option>
val f : ('a -> Task<'b>)
Multiple items
type Task =
  new : action:Action -> Task + 7 overloads
  member AsyncState : obj
  member ConfigureAwait : continueOnCapturedContext:bool -> ConfiguredTaskAwaitable
  member ContinueWith : continuationAction:Action<Task> -> Task + 19 overloads
  member CreationOptions : TaskCreationOptions
  member Dispose : unit -> unit
  member Exception : AggregateException
  member GetAwaiter : unit -> TaskAwaiter
  member Id : int
  member IsCanceled : bool
  ...

--------------------
type Task<'TResult> =
  inherit Task
  new : function:Func<'TResult> -> Task<'TResult> + 7 overloads
  member ConfigureAwait : continueOnCapturedContext:bool -> ConfiguredTaskAwaitable<'TResult>
  member ContinueWith : continuationAction:Action<Task<'TResult>> -> Task + 19 overloads
  member GetAwaiter : unit -> TaskAwaiter<'TResult>
  member Result : 'TResult
  static member Factory : TaskFactory<'TResult>

--------------------
Task(action: System.Action) : Task
Task(action: System.Action, cancellationToken: System.Threading.CancellationToken) : Task
Task(action: System.Action, creationOptions: TaskCreationOptions) : Task
Task(action: System.Action<obj>, state: obj) : Task
Task(action: System.Action, cancellationToken: System.Threading.CancellationToken, creationOptions: TaskCreationOptions) : Task
Task(action: System.Action<obj>, state: obj, cancellationToken: System.Threading.CancellationToken) : Task
Task(action: System.Action<obj>, state: obj, creationOptions: TaskCreationOptions) : Task
Task(action: System.Action<obj>, state: obj, cancellationToken: System.Threading.CancellationToken, creationOptions: TaskCreationOptions) : Task

--------------------
Task(function: System.Func<'TResult>) : Task<'TResult>
Task(function: System.Func<'TResult>, cancellationToken: System.Threading.CancellationToken) : Task<'TResult>
Task(function: System.Func<'TResult>, creationOptions: TaskCreationOptions) : Task<'TResult>
Task(function: System.Func<obj,'TResult>, state: obj) : Task<'TResult>
Task(function: System.Func<'TResult>, cancellationToken: System.Threading.CancellationToken, creationOptions: TaskCreationOptions) : Task<'TResult>
Task(function: System.Func<obj,'TResult>, state: obj, cancellationToken: System.Threading.CancellationToken) : Task<'TResult>
Task(function: System.Func<obj,'TResult>, state: obj, creationOptions: TaskCreationOptions) : Task<'TResult>
Task(function: System.Func<obj,'TResult>, state: obj, cancellationToken: System.Threading.CancellationToken, creationOptions: TaskCreationOptions) : Task<'TResult>
Task.FromResult<'TResult>(result: 'TResult) : Task<'TResult>
val bindTask : f:('a -> Task<'b option>) -> _arg1:'a option -> Task<'b option>
val f : ('a -> Task<'b option>)
val mapAsync : f:('a -> Async<'b>) -> _arg1:'a option -> Async<'b option>
val f : ('a -> Async<'b>)
Multiple items
type Async =
  static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
  static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
  static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
  static member AwaitTask : task:Task -> Async<unit>
  static member AwaitTask : task:Task<'T> -> Async<'T>
  static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
  static member CancelDefaultToken : unit -> unit
  static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
  static member Choice : computations:seq<Async<'T option>> -> Async<'T option>
  static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
  ...

--------------------
type Async<'T> =
val async : AsyncBuilder
val result : 'b
val bindAsync : f:('a -> Async<'b option>) -> _arg1:'a option -> Async<'b option>
val f : ('a -> Async<'b option>)
namespace System.Runtime
namespace System.Runtime.CompilerServices
Multiple items
type ExtensionAttribute =
  inherit Attribute
  new : unit -> ExtensionAttribute

--------------------
ExtensionAttribute() : ExtensionAttribute
val x : Option<('a -> 'b)>
Multiple items
module Option

from TiraxTech.Foundation

--------------------
module Option

from Microsoft.FSharp.Core
val p : 'a
val x : 'a option option
val x : Option<'T>
val fsome : ('T -> unit)
val fsome : ('T -> 'a)
val fnone : (unit -> 'a)
val predicate : ('T -> bool)
Multiple items
val filter : predicate:('a -> bool) -> ('a option -> 'a option)

--------------------
val filter : predicate:('T -> bool) -> option:'T option -> 'T option
val get : option:'T option -> 'T
val def : 'T
val f : (unit -> 'T)
val fnone : (unit -> 'T option)
val v : (unit -> 'T)
val defaultWith : defThunk:(unit -> 'T) -> option:'T option -> 'T
val y : ('T -> 'a option)
val bind : binder:('T -> 'U option) -> option:'T option -> 'U option
val f : ('T -> 'a)
val f : ('T -> Task<'a option>)
val f : ('T -> Async<'a>)
val f : ('T -> Async<'a option>)
Multiple items
module Result

from Microsoft.FSharp.Core

--------------------
[<Struct>]
type Result<'T,'TError> =
  | Ok of ResultValue: 'T
  | Error of ErrorValue: 'TError
val get : right:('a -> 'b) -> wrong:('c -> 'b) -> _arg1:Result<'a,'c> -> 'b
val right : ('a -> 'b)
val wrong : ('c -> 'b)
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
val y : 'a
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>
val x : 'c
val mapAll : fright:('a -> 'b) -> fwrong:('c -> 'd) -> (Result<'a,'c> -> Result<'b,'d>)
val fright : ('a -> 'b)
val fwrong : ('c -> 'd)
val ap : other:Result<'a,'b> -> fwrong:('c -> 'b) -> (Result<('a -> 'd),'c> -> Result<'d,'b>)
[<Struct>]
val other : Result<'a,'b>
val fwrong : ('c -> 'b)
val f : ('a -> 'd)
val map : mapping:('T -> 'U) -> result:Result<'T,'TError> -> Result<'U,'TError>
val isError : x:Result<'a,'b> -> bool
[<Struct>]
val x : Result<'a,'b>
val isOk : x:Result<'a,'b> -> bool
val join : r:Result<Result<'a,'b>,'b> -> Result<'a,'b>
[<Struct>]
val r : Result<Result<'a,'b>,'b>
val bindAll : f:('a -> Result<'c,'d>) -> fwrong:('b -> Result<'c,'d>) -> (Result<'a,'b> -> Result<'c,'d>)
val f : ('a -> Result<'c,'d>)
val fwrong : ('b -> Result<'c,'d>)
val getOrDefault : def:'a -> (Result<'a,'b> -> 'a)
val getOrElse : def:('a -> 'b) -> (Result<'b,'a> -> 'b)
val def : ('a -> 'b)
val mapTask : f:('a -> Task<'c>) -> fwrong:('b -> 'd) -> _arg1:Result<'a0,'b> -> Task<Result<'b1,'d>>
val f : ('a -> Task<'c>)
val fwrong : ('b -> 'd)
val y : 'b
val bindTask : f:('a -> Task<Result<'c,'d>>) -> fwrong:('b -> 'd) -> _arg1:Result<'a,'b> -> Task<Result<'c,'d>>
val f : ('a -> Task<Result<'c,'d>>)
val mapAsync : f:('a -> Async<'c>) -> fwrong:('b -> 'd) -> _arg1:Result<'a,'b> -> Async<Result<'c,'d>>
val f : ('a -> Async<'c>)
val result : 'c
val bindAsync : f:('a -> Async<Result<'c,'d>>) -> fwrong:('b -> 'd) -> _arg1:Result<'a,'b> -> Async<Result<'c,'d>>
val f : ('a -> Async<Result<'c,'d>>)
Multiple items
type ResultBuilder =
  new : unit -> ResultBuilder
  member Bind : x:Result<'a,'b> * f:('a -> Result<'c,'b>) -> Result<'c,'b>
  member Delay : f:(unit -> Result<'a,'b>) -> (unit -> Result<'a,'b>)
  member Return : v:'c -> Result<'c,'a>
  member ReturnFrom : v:Result<'a,'b> -> Result<'a,'b>
  member Run : f:(unit -> Result<'a,'b>) -> Result<'a,'b>
  member TryWith : f:(unit -> Result<'a,'b>) * catch:(exn -> Result<'a,'b>) -> Result<'a,'b>
  member Using : v:'a * f:('a -> Result<'b,'c>) -> Result<'b,'c>

--------------------
new : unit -> ResultBuilder
Multiple items
module Result

from TiraxTech.Foundation

--------------------
module Result

from Microsoft.FSharp.Core

--------------------
[<Struct>]
type Result<'T,'TError> =
  | Ok of ResultValue: 'T
  | Error of ErrorValue: 'TError
val f : ('a -> Result<'c,'b>)
val bind : binder:('T -> Result<'U,'TError>) -> result:Result<'T,'TError> -> Result<'U,'TError>
val v : 'c
[<Struct>]
val v : Result<'a,'b>
val f : ('a -> Result<'b,'c>)
val f : (unit -> Result<'a,'b>)
val catch : (exn -> Result<'a,'b>)
type exn = System.Exception
val e : exn
val result : ResultBuilder
val memoizeWithKey : keyGetter:('input -> 'key) -> f:('input -> 'output) -> ('input -> 'output)


 memoizeWithKey: ('input -> 'key) -> ('input -> 'output) -> ('input -> 'output)
val keyGetter : ('input -> 'key)
val f : ('input -> 'output)
val dict : System.Collections.Concurrent.ConcurrentDictionary<'key,'output>
namespace System.Collections.Concurrent
Multiple items
type ConcurrentDictionary<'TKey,'TValue> =
  new : unit -> ConcurrentDictionary<'TKey, 'TValue> + 6 overloads
  member AddOrUpdate : key:'TKey * addValueFactory:Func<'TKey, 'TValue> * updateValueFactory:Func<'TKey, 'TValue, 'TValue> -> 'TValue + 2 overloads
  member Clear : unit -> unit
  member ContainsKey : key:'TKey -> bool
  member Count : int
  member GetEnumerator : unit -> IEnumerator<KeyValuePair<'TKey, 'TValue>>
  member GetOrAdd : key:'TKey * valueFactory:Func<'TKey, 'TValue> -> 'TValue + 2 overloads
  member IsEmpty : bool
  member Item : 'TKey -> 'TValue with get, set
  member Keys : ICollection<'TKey>
  ...

--------------------
System.Collections.Concurrent.ConcurrentDictionary() : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(collection: System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<'TKey,'TValue>>) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(comparer: System.Collections.Generic.IEqualityComparer<'TKey>) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(concurrencyLevel: int, capacity: int) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(collection: System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<'TKey,'TValue>>, comparer: System.Collections.Generic.IEqualityComparer<'TKey>) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(concurrencyLevel: int, collection: System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<'TKey,'TValue>>, comparer: System.Collections.Generic.IEqualityComparer<'TKey>) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
System.Collections.Concurrent.ConcurrentDictionary(concurrencyLevel: int, capacity: int, comparer: System.Collections.Generic.IEqualityComparer<'TKey>) : System.Collections.Concurrent.ConcurrentDictionary<'TKey,'TValue>
val memoizedFunc : ('input -> 'output)
val input : 'input
val key : 'key
System.Collections.Concurrent.ConcurrentDictionary.TryGetValue(key: 'key, value: byref<'output>) : bool
val x : 'output
val answer : 'output
System.Collections.Concurrent.ConcurrentDictionary.TryAdd(key: 'key, value: 'output) : bool
val ignore : value:'T -> unit
val memoize : f:('a -> 'b) -> ('a -> 'b)
Raw view Test code New version

More information

Link:http://fssnip.net/85u
Posted:3 years ago
Author:Ruxo Zheng
Tags: #result , #option