FruityFoundation/FsBase/Extensions.fs

36 lines
1.1 KiB
Forth
Raw Permalink Normal View History

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
open FruityFoundation.Base.Structures
2023-09-03 22:06:54 -04:00
module Array =
let toReadOnlyCollection (a : 'a array) = a :> 'a IReadOnlyCollection
module Option =
let toMaybe : 'a option -> Maybe<'a> = function
| Some x -> x |> Maybe.Create
| None -> Maybe.Empty ()
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