Giter VIP home page Giter VIP logo

Comments (1)

gusty avatar gusty commented on June 11, 2024

@anpin Sorry for the late reply and thanks for taking the time for reporting this.

It seems to me you have an issue understanding the Validation mechanics: the 'Error type has to be something like a semigroup that is a type which supports a kind of "self folding" operation, in F#+ that operator should be static member (+).

So, to fix the issue you can define your Errors type as Error and in turn make Errors a list of Error:

#r "nuget: FSharpPlus"

open FSharpPlus
open FSharpPlus.Data
open System.Threading.Tasks

[<Struct>]
type Error =
  | UnexpectedError of string

type Errors = Error list

[<Struct>]
type dto = {
  A : string
  B : string
}
[<Struct>]
type TypedTuple<'a,'b> = TypedTuple of struct('a option *  'b option )

let validateA (TypedTuple (did, dto): TypedTuple<string,dto>)   =
  match did with
  | Some _ -> Validation<Errors, _>.Success dto
  | None -> Validation<Errors, _>.Failure [Error.UnexpectedError "ooops"]
  |> Task.FromResult

Another option could be defining internally your original Error as a list and add the (+) static member.

When you use a string it just works because string is a semigroup and it supports the + operation, although the error accumulation will be a bit awkward as it will concatenate all error messages.

from fsharpplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.