Git Product home page Git Product logo

Comments (4)

JamesRandall avatar JamesRandall commented on July 19, 2024

Thanks, I'll take a look. I came across Chessie the other day while researching something else funnily enough.

With regard to Warn - any thoughts on how to add that while keeping the syntax super clean? Initially that's why I avoided it (well that and that I didn't need it allowed me to duck it!!).

ROP - yes, but I came across that by way of Kit Eason's book rather than (the excellent and well thumbed by me over the last six months) Fun and Profit.

Thanks for the input :)

from accidentalfish.fsharp.validation.

JamesRandall avatar JamesRandall commented on July 19, 2024

Actually... just had a nice idea about Warn. Will take a look later today.

from accidentalfish.fsharp.validation.

JamesRandall avatar JamesRandall commented on July 19, 2024

Something like this:

validate (fun r -> r.title) [
    isNotEmpty
    hasMaxLengthOf 128
    warn [
        hasMinLengthOf 32
    ]
]

from accidentalfish.fsharp.validation.

goldfish1974 avatar goldfish1974 commented on July 19, 2024

Yeah, that looks ok for associating additional info along with the validation.

I'm not sure how it fits in the context of validation though. Perhaps the warn could indicate interdependent fields? If Field1 is valid then Warn other Fields is also flip from optional to required (e.g. Address must have a Postal code or State). I often nest validation in this case though as it means Field1 doesn't have dependencies on other fields.

In your example, above, I can imagine Warn [ passwordWeak ] could be a suitable use.

The warn concept actually fits with Chessie even more closly.

Chessie defines the Result as:

type Result<'TSuccess, 'TMessage> =
| Ok of 'TSuccess * 'TMessage list
| Bad of 'TMessage list

OK is OK with an empty list, Warn is OK with a list of messages and Bad represents the failure.

There are a bunch of active patterns as well as apply, lift and map type functions in Chessie so that you can compose each of the functions together using |>. At the bottom of the chained functions, you effectively get a list of errors.

I used it heavily in a DSL that I made to create a tree of functions that extract the data from the HTML. The DSL -> Result<FunctionRoot, DSLErrors>. when I run FunctionRoot(HtmlDom) -> Result<Json, ParseErrors>.

The error list that came out was actually a complete list of errors for the whole DSL as well as each of the branches that run when the DSL "program" ran. That way, I didn't have to fix, test, fix etc.

I didn't really have a use for Warn in that case but I felt that Warn is domain specific and the above Chessie Result type for OK having the message list was probably the best fit for Warn (even though I didn't use it).

from accidentalfish.fsharp.validation.

Related Issues (3)

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.