Skip to content

Commit

Permalink
DRYer
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jul 2, 2023
1 parent ddaebf9 commit f2c9885
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions kittens/transfer/ftc.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ func split_for_transfer(data []byte, file_id string, mark_last bool, callback fu
chunk = data[:chunk_size]
}
data = data[len(chunk):]
ac := Action_data
if mark_last && len(data) == 0 {
ac = Action_end_data
}
callback(&FileTransmissionCommand{Action: ac, File_id: file_id, Data: chunk})
callback(&FileTransmissionCommand{
Action: utils.IfElse(mark_last && len(data) == 0, Action_end_data, Action_data),
File_id: file_id, Data: chunk})
}
}
7 changes: 7 additions & 0 deletions tools/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,10 @@ func SetStructDefaults(v reflect.Value) (err error) {
}
return
}

func IfElse[T any](condition bool, if_val T, else_val T) T {
if condition {
return if_val
}
return else_val
}

0 comments on commit f2c9885

Please sign in to comment.