operator

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Unknown <applicant@airwallex.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrStackTooSmall = errors.New("expected at least 2 items in the stack")

ErrStackTooSmall is raised when the stack has too little items.

Functions

This section is empty.

Types

type AdditionOperator

type AdditionOperator struct {
	ArithmeticOperator
}

AdditionOperator is an implementation of the operator.Operator interface which performs the addition of the last 2 numbers on the stack.

func NewAdditionOperator

func NewAdditionOperator() AdditionOperator

NewAdditionOperator creates a new instance of the AdditionOperator

func (AdditionOperator) Identifier

func (o AdditionOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack

func (AdditionOperator) Operate

func (o AdditionOperator) Operate(s *stack.Stack) (err error)

Operate adds two numbers on the stack, it leverages the ArtithmeticOperator to easily define the last two digits and sets the return value.

type ArithmeticOperator

type ArithmeticOperator struct{}

ArithmeticOperator is a base struct which implements some helper functions to perform common operations on the stack. FYI: This is only here to demonstrate inheritance in Golang since the implementation is so simple, the Get method should just be a private method in this package

func NewArithmeticOperator

func NewArithmeticOperator() ArithmeticOperator

NewArithmeticOperator creates a new base implementation for the arithmetic operator

func (ArithmeticOperator) Get

func (o ArithmeticOperator) Get(s *stack.Stack) (a float64, b float64, err error)

Get retrieves the last two values of the stack, or an error when the stack is too small.

type ClearOperator

type ClearOperator struct{}

ClearOperator provides a simple interface to pop the last value of the stack.

func NewClearOperator

func NewClearOperator() ClearOperator

NewClearOperator creates a new ClearOperator instance

func (ClearOperator) Identifier

func (o ClearOperator) Identifier() string

Identifier returns the operation a user can input whilst performing operations on the stack.

func (ClearOperator) Operate

func (o ClearOperator) Operate(s *stack.Stack) (err error)

Operate pops the last item from the stack.

type DivisionOperator

type DivisionOperator struct {
	ArithmeticOperator
}

DivisionOperator is an implementation of the operator.Operator interface which performs the division of the last 2 numbers on the stack.

func NewDivisionOperator

func NewDivisionOperator() DivisionOperator

NewDivisionOperator is a factory method to construct a new DisivionOperator instance.

func (DivisionOperator) Identifier

func (o DivisionOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack

func (DivisionOperator) Operate

func (o DivisionOperator) Operate(s *stack.Stack) (err error)

Operate divides two numbers on the stack, it leverages the ArtithmeticOperator to easily define the last two digits and sets the return value.

type MultiplicationOperator

type MultiplicationOperator struct {
	ArithmeticOperator
}

MultiplicationOperator provides a simple interface to compute the multiple of the last two values on the stack.

func NewMultiplicationOperator

func NewMultiplicationOperator() MultiplicationOperator

NewMultiplicationOperator is a factory method to instantiate a new MultiplicationOperator with a default ArtithmeticOperator.

func (MultiplicationOperator) Identifier

func (o MultiplicationOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack.

func (MultiplicationOperator) Operate

func (o MultiplicationOperator) Operate(s *stack.Stack) (err error)

Operate gets the last two entries of the stack and performs multiplication on it.

type Operator

type Operator interface {
	Identifier() string
	Operate(*stack.Stack) error
}

Operator defines the common interface for any operator. It provides the functionality to operate a command on a stack, allowing the operator to pop and push items from the stack.

type SinOperator

type SinOperator struct{}

SqrtOperator provides a simple interface to compute the sinoid value of the last value on the stack

func NewSinOperator

func NewSinOperator() SinOperator

NewSinOperator is a factory method to instantiate a new SinOperator.

func (SinOperator) Identifier

func (o SinOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack.

func (SinOperator) Operate

func (o SinOperator) Operate(s *stack.Stack) (err error)

Operate gets the last entry of the stack and performs math.Sin on it.

type SqrtOperator

type SqrtOperator struct{}

SqrtOperator provides a simple interface to compute the square root of the last value on the stack

func NewSqrtOperator

func NewSqrtOperator() SqrtOperator

NewSubtractionOperator is a factory method to instantiate a new SqrtOperator

func (SqrtOperator) Identifier

func (o SqrtOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack

func (SqrtOperator) Operate

func (o SqrtOperator) Operate(s *stack.Stack) (err error)

Operate gets the last entry of the stack and performs math.Sqrt on it.

type SubtractionOperator

type SubtractionOperator struct {
	ArithmeticOperator
}

SubtractionOperator provides a simple interface to compute two numbers in the stack.

func NewSubtractionOperator

func NewSubtractionOperator() SubtractionOperator

NewSubtractionOperator is a factory method to instantiate a new SubtractionOperator seeded with a default ArithmeticOpertor.

func (SubtractionOperator) Identifier

func (o SubtractionOperator) Identifier() string

Identifier returns the operation a user can input whilst performing arithmetic operations on the stack

func (SubtractionOperator) Operate

func (o SubtractionOperator) Operate(s *stack.Stack) (err error)

Operate gets the last two entries from the stack and then performs the subtraction of both entries.

type UndoOperator

type UndoOperator struct{}

UndoOperator provides a simple interface to pop the last value of the stack.

func NewUndoOperator

func NewUndoOperator() UndoOperator

NewUndoOperator creates a new UndoOperator instance

func (UndoOperator) Identifier

func (o UndoOperator) Identifier() string

Identifier returns the operation a user can input whilst performing operations on the stack.

func (UndoOperator) Operate

func (o UndoOperator) Operate(s *stack.Stack) (err error)

Operate pops the last item from the stack.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL