Git Product home page Git Product logo

valor's People

Contributors

phelmkamp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

binaryphile

valor's Issues

Add a linter

Check for MustOk without IsOk, ignoring Ok result, etc.

result: variadic Errorf

Consider accepting variadic values to Errorf like fmt.Errorf. Find %w in message and insert error before call to fmt.Errorf.

optional: add helpers for map index, channel receive, type assertion

Map index, channel receive, and type assertion expressions only return the extra boolean if dictated by the assignment. To use with optional.Value you must first assign to two variables, e.g.:

var m map[string]string
v, ok := m["foo"]
val := optional.Of(v, ok)

Instead, a helper could do the assignment internally and return the populated optional.Value, e.g.:

val := optional.OfIndex(m, "foo")

optional: implement JSON marshaling

Marshaling a not-ok Value to JSON should omit it as if it were empty paired with omitempty. Marshaling an ok Value should simply marshal the underlying value.

Then, during unmarshal, the Value will be left as empty if omitted which means "not ok". Unmarshaling a present value will produce an ok Value.

optional/result: add deconstruct method

A method to deconstruct a Value as a separate value and bool will enable interoperability with any other "optional" types that might be out there. For example:

func (val Value[T]) Get() (T, bool) {
    return val.v, val.ok
}

var other otheropt.Of(val.Get())

Alternative names:

  • Unpack
  • Unzip

result: handle OfError(nil)

OfError(nil) is currently equivalent to OfOk(<zero>) which seems incorrect. Instead it should probably report a nil error and a not-ok value.

This can arise when taking the result of a function that only returns error. In that case, what should the type of T be?

Add an enum package

An enum can be defined as a set of allowed values and an optional of the currently selected one.

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.