Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 856 Bytes

Assign.md

File metadata and controls

51 lines (35 loc) · 856 Bytes

Assign

A Callbag sinker that will assign the latest next event value to a Class or Struct. And it returns a Cancellable.

Examples

assign to variable in class:

class MyClass {
  var element: Int = 0
}

var myClass = MyClass()

_ = just(1)
  |> assign(to: \.element, on: myClass)

print(myClass.element) // 1

assign to variable in struct:

struct MyStruct {
  var element: Int = 0
}

var myStruct = MyStruct()

_ = just(1)
  |> assign(to: \.element, on: &myStruct)

print(myStruct.element)

assign to struct/class:

var element: Int = 0

_ = just(1)
  |> assign(to: &element)

print(element)