Why toSet return Function()<Kotlin.Unit>?

I am very new to Korlin programming. I have written this block of code

// attendanceJson: Array<AttendanceJson>
val list = attendanceJson
            .map { i ->
                    val o = StudentAttendance()
                    o.attendanceStatus = i.i
                    o.student = studentService.findById(i.t)

which return list of Function()<Kotlin.Unit>. But I need Set of StudentArrendance. DOC said toSet() function will return given type of Set.

How to do this ? And what is Function()<Kotlin.Unit>, and what is the purpose ?

“o.student” is “o.setStudent” and returns Unit, therefore your block in map returns Unit.

Do you want map every i with Unit?

Try this:

.map { i -> StudentAttendance().apply {
                attendanceStatus = i.i
                student = studentService.findById(i.t)

this block returns a StudentAttendance after have applied some methods.

1 Like