This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.ListBuffer | |
case class Student(rollNum: Int, name: String) | |
trait Students { | |
val students = ListBuffer(Student(1, "Ayush"), Student(2, "deepankar")) | |
def fetchStudents: ListBuffer[Student] = students | |
def addStudent(student: Student): ListBuffer[Student] = { | |
student +: students | |
} | |
def updateStudent(student: Student): ListBuffer[Student] = { | |
val oldRecord = students.filter(_.rollNum == student.rollNum) | |
students --= oldRecord | |
student +: students | |
} | |
def deleteStudent(rollNum: Int): ListBuffer[Student] = { | |
val deleteRecord = students.filter(_.rollNum == rollNum) | |
students --= deleteRecord | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment