---
# System prepended metadata

title: Untitled

---

```
package main 

import ( 
	"fmt"
) 

type Book struct {
	name string
	author string
}

func (book Book) showBook() {
	fmt.Println("Book name: ", book.name)
	fmt.Println("Book author: ", book.author)
}

func (book Book) isEqual(anotherBook Book) bool {
	if (book.name == anotherBook.name && book.author == anotherBook.author) {
		return true
	}
	return false
}

type Library struct {
	name string
	books []Book
}

func (library Library) addBook(book Book) Library {
	library.books = append(library.books, book)
	return library
}

func (library Library) removeBook(book Book) Library {
	index := -1
	for i := 0; i < len(library.books); i++ {
		if (library.books[i].isEqual(book)) {
			index = i;
			break;
		}
	}
	if (index != -1) {
		library.books = append(library.books[:index], library.books[index+1:]...)
	}
	return library
}

func (library Library) showLibrary() {
	fmt.Println("Displaying: ", library.name)
	for i := 0; i < len(library.books); i++ {
		fmt.Println("Book no: ", i)
		library.books[i].showBook()
		fmt.Println()
	}
}

func main() { 
	book1 := Book{name: "Computer Programming", author: "Tamim Shahriar Subin"}
	book2 := Book{name: "Programming in C", author: "Stephen G. Kochan"}
	
	library := Library{name: "Oxford Library", books: make([]Book, 0)}
	library = library.addBook(book1)
	library = library.addBook(book2)
	library.showLibrary()
	
	library = library.removeBook(book1)
	
	fmt.Println("# After removing 'book1':")
	library.showLibrary() 
	
	library = library.addBook(book1).removeBook(book1).addBook(book1)
	
	fmt.Println("# After A.add().remove().add(): ")
	library.showLibrary() 
} 
```