mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
eval/vals: Comment and rename.
This commit is contained in:
parent
873d8eeeaf
commit
2e51774b81
|
@ -138,7 +138,7 @@ func (gp GlobPattern) Concat(v interface{}) (interface{}, error) {
|
|||
return gp, nil
|
||||
}
|
||||
|
||||
return nil, vals.ErrCatNotImplemented
|
||||
return nil, vals.ErrConcatNotImplemented
|
||||
}
|
||||
|
||||
func (gp GlobPattern) RConcat(v interface{}) (interface{}, error) {
|
||||
|
@ -150,7 +150,7 @@ func (gp GlobPattern) RConcat(v interface{}) (interface{}, error) {
|
|||
return GlobPattern{glob.Pattern{Segments: segs}, gp.Flags, gp.Buts}, nil
|
||||
}
|
||||
|
||||
return nil, vals.ErrCatNotImplemented
|
||||
return nil, vals.ErrConcatNotImplemented
|
||||
}
|
||||
|
||||
func (gp *GlobPattern) mustGetLastWildSeg() glob.Wild {
|
||||
|
|
|
@ -5,18 +5,28 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
Concatter interface {
|
||||
Concat(v interface{}) (interface{}, error)
|
||||
}
|
||||
// Concatter wraps the Concat method. See Concat for how it is used.
|
||||
type Concatter interface {
|
||||
// Concat concatenates the receiver with another value, the receiver being
|
||||
// the left operand. If concatenation is not supported for the given value,
|
||||
// the method can return the special error type ErrCatNotImplemented.
|
||||
Concat(v interface{}) (interface{}, error)
|
||||
}
|
||||
|
||||
RConcatter interface {
|
||||
RConcat(v interface{}) (interface{}, error)
|
||||
}
|
||||
)
|
||||
// RConcatter wraps the RConcat method. See Concat for how it is used.
|
||||
type RConcatter interface {
|
||||
RConcat(v interface{}) (interface{}, error)
|
||||
}
|
||||
|
||||
var ErrCatNotImplemented = errors.New("cat not implemented")
|
||||
// ErrConcatNotImplemented is a special error value used to signal that
|
||||
// concatenation is not implemented. See Concat for how it is used.
|
||||
var ErrConcatNotImplemented = errors.New("cat not implemented")
|
||||
|
||||
// Concat concatenates two values. If both operands are strings, it returns lhs
|
||||
// + rhs, nil. If the left operand implements Concatter, it calls
|
||||
// lhs.Concat(rhs). If lhs doesn't implement the interface or returned
|
||||
// ErrConcatNotImplemented, it then calls rhs.RConcat(lhs). If all attempts
|
||||
// fail, it returns nil and an error.
|
||||
func Concat(lhs, rhs interface{}) (interface{}, error) {
|
||||
if v, ok := tryConcatBuiltins(lhs, rhs); ok {
|
||||
return v, nil
|
||||
|
@ -24,14 +34,14 @@ func Concat(lhs, rhs interface{}) (interface{}, error) {
|
|||
|
||||
if lhs, ok := lhs.(Concatter); ok {
|
||||
v, err := lhs.Concat(rhs)
|
||||
if err != ErrCatNotImplemented {
|
||||
if err != ErrConcatNotImplemented {
|
||||
return v, err
|
||||
}
|
||||
}
|
||||
|
||||
if rhs, ok := rhs.(RConcatter); ok {
|
||||
v, err := rhs.RConcat(lhs)
|
||||
if err != ErrCatNotImplemented {
|
||||
if err != ErrConcatNotImplemented {
|
||||
return v, err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user