spf13 / spf13/cast

Add default value to To_____ methods

Open
#218 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
4k
Forks
337
Avg merge
15m
Merged PRs (30d)
1

Description

I suggest adding a default value to all 'To___' methods.

Before:

// ToBool casts an interface to a bool type.
func ToBool(i interface{}) bool {
	v, _ := ToBoolE(i)
	return v
}

After:

// ToBool casts an interface to a bool type.
func ToBool(i interface{}, default ...bool) bool {
	v, err := ToBoolE(i)
        if err != nil && len(default) > 0 {
            return default[0]
        }
	return v
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating every To___ method and its corresponding To___E method in the repository, then review how their current return values and errors behave. Done means the requested default-value behavior is consistently defined for all such methods without changing existing behavior when no default is supplied.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.