2022-03-31 20:34:17 -04:00
|
|
|
namespace FruityFoundation.FsBase
|
2023-09-03 22:06:54 -04:00
|
|
|
open System.Collections.Generic
|
2024-05-03 00:54:10 -04:00
|
|
|
open System.Runtime.CompilerServices
|
2022-03-31 20:34:17 -04:00
|
|
|
open FruityFoundation.Base.Structures
|
|
|
|
|
2023-09-03 22:06:54 -04:00
|
|
|
module Array =
|
|
|
|
let toReadOnlyCollection (a : 'a array) = a :> 'a IReadOnlyCollection
|
|
|
|
|
2022-12-23 12:36:02 -05:00
|
|
|
module Option =
|
|
|
|
let toMaybe : 'a option -> Maybe<'a> = function
|
2024-04-30 13:18:51 -04:00
|
|
|
| Some x -> x |> Maybe.Create
|
2022-03-31 20:34:17 -04:00
|
|
|
| None -> Maybe.Empty ()
|
|
|
|
|
2022-12-23 12:36:02 -05:00
|
|
|
let fromMaybe : Maybe<'a> -> 'a option = function
|
|
|
|
| x when x.HasValue -> Some x.Value
|
|
|
|
| _ -> None
|
2024-05-03 00:54:10 -04:00
|
|
|
|
|
|
|
module ValueOption =
|
|
|
|
let toMaybe : 'a ValueOption -> Maybe<'a> = function
|
|
|
|
| ValueSome x -> x |> Maybe.Create
|
|
|
|
| ValueNone -> Maybe.Empty ()
|
|
|
|
|
|
|
|
let fromMaybe : Maybe<'a> -> 'a ValueOption = function
|
|
|
|
| x when x.HasValue -> ValueSome x.Value
|
|
|
|
| _ -> ValueNone
|
|
|
|
|
|
|
|
type OptionMaybeInterop =
|
|
|
|
[<Extension>]
|
|
|
|
static member ToMaybe (x : 'a option) = Option.toMaybe x
|
|
|
|
[<Extension>]
|
|
|
|
static member ToMaybe (x : 'a ValueOption) = ValueOption.toMaybe x
|
|
|
|
[<Extension>]
|
|
|
|
static member ToOption (x : 'a Maybe) = Option.fromMaybe x
|
|
|
|
[<Extension>]
|
|
|
|
static member ToValueOption (x : 'a Maybe) = ValueOption.fromMaybe x
|