package api

type BehaviorSubjectStruct struct {
	Subscriber
	initial interface{}
}

func BehaviorSubject(initial ...interface{}) *BehaviorSubjectStruct {
	var (
		value interface{}
	)
	if len(initial) > 0 {
		value = initial[0]
	}

	return &BehaviorSubjectStruct{
		initial:    value,
		Subscriber: *NewSubscriber(),
	}
}

func (behavior *BehaviorSubjectStruct) Subscribe(handles ...func(...interface{})) (subscription *Subscription) {

	subscription = behavior.Subscriber.Subscribe(handles...)

	if behavior.initial != nil {
		subscription.Next(behavior.initial)
	}

	return
}
