Created
February 2, 2025 20:06
-
-
Save OnurGumus/355957f96795a4584f6bb013079e57a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open FCQRS.Model.Data | |
open FCQRS.Model.Aether | |
open FCQRS.Model.Aether.Operators | |
open FsToolkit.ErrorHandling | |
module Domain = | |
type FirstName = | |
private | |
| FirstName of ShortString | |
static member Value_: ValidatedLens<FirstName, ShortString,string> = | |
(fun (FirstName u) -> u), | |
(fun (shortString: ShortString) _ -> | |
let v = shortString |> ValueLens.Value | |
if v.Length > 10 then (Error ("cannot be long")) | |
else | |
shortString |> FirstName |> Ok ) | |
override this.ToString() = (ValueLens.Value this).ToString() | |
type LastName = | |
private | |
| LastName of ShortString | |
static member Value_: Lens<LastName, ShortString> = | |
(fun (LastName u) -> u), (fun (g: ShortString) _ -> g |> LastName) | |
override this.ToString() = (ValueLens.Value this).ToString() | |
type Person = | |
private | |
| Person of | |
{| FirstName: FirstName | |
LastName: LastName |} | |
static member FirstName_ : Lens<Person, FirstName> = | |
(fun (Person p) -> p.FirstName), (fun (v) (Person p) -> Person {| p with FirstName = v; |}) | |
static member Value_ | |
: ValidatedLens< _,_, _> = | |
(fun (Person p) -> | |
{| FirstName = p.FirstName |> ValueLens.Value |> ValueLens.Value | |
LastName = p.LastName |> ValueLens.Value |> ValueLens.Value |}), | |
(fun (v) _ -> | |
result{ | |
let! (firstName:FirstName) =v.FirstName |> ValueLens.TryCreate |> Result.value |> ValueLens.TryCreate | |
return | |
Person | |
{| FirstName =firstName; LastName = v.LastName |> ValueLens.CreateAsResult |> Result.value |} | |
} | |
) | |
override this.ToString() = (ValueLens.Value this).ToString() | |
open Domain | |
let shortString : ShortString= "Foo" |> ValueLens.TryCreate |> Result.value | |
let innerValue = shortString |> ValueLens.Value | |
let firstName : FirstName = shortString |> ValueLens.TryCreate |> Result.value | |
let lastName: LastName = shortString |> ValueLens.Create | |
let p :Person = {| FirstName = "Onur Onur " ; LastName = "Gumus"|} |> ValueLens.TryCreate |> Result.value | |
let newPerson = (firstName ^= Person.FirstName_ ) p | |
printf "%A" <| newPerson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment