github.com/blend/go-sdk@v1.20240719.1/validate/when.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package validate
     9  
    10  // When returns the result of the "passes" validator if the predicate returns true,
    11  // otherwise it returns nil.
    12  func When(predicate func() bool, passes Validator) Validator {
    13  	return func() error {
    14  		if predicate() {
    15  			return passes()
    16  		}
    17  		return nil
    18  	}
    19  }