예제 #1
0
파일: cyclic.go 프로젝트: gaowt1/lists
//	Determines if another object is equivalent to the CycList
//	Two CycLists are identical if they both have the same number of nodes, and the head of each node is the same
func (c CycList) Equal(o interface{}) (r bool) {
	switch o := o.(type) {
	case *CycList:
		r = o != nil && c.ListHeader.Equal(o.ListHeader)
	case CycList:
		r = c.ListHeader.Equal(o.ListHeader)
	default:
		raw.Catch(func() {
			r = c.start.(Equatable).Equal(o)
		})
	}
	return
}
예제 #2
0
파일: sexp.go 프로젝트: feyeleanor/sexp
/*func While(container interface{}, f func(interface{}) bool) (i int) {
	raw.Catch(func() {
		Each(container, func(x interface{}) {
			if f(x) {
				i++
			} else {
				raw.Throw()
			}
		})
	})
	return
}

//	Until processes values from a container until a condition is true or until the end of the container is reached.
//	Returns the count of items which fail the test.
func Until(container interface{}, f func(interface{}) bool) (i int) {
	raw.Catch(func() {
		Each(container, func(x interface{}) {
			if f(x) {
				raw.Throw()
			} else {
				i++
			}
		})
	})
	return
}

func Any(container interface{}, f func(interface{}) bool) (b bool) {
	if l := Until(container, f); l > 0 {
		 b = l < Len(container)
	}
	return
}

func All(container interface{}, f func(interface{}) bool) (b bool) {
	if l := While(container, f); l > 0 {
		b = l == Len(container)
	}
	return
}

func None(container interface{}, f func(interface{}) bool) (b bool) {
	return Until(container, f) == Len(container)
}
*/
func One(container interface{}, f func(interface{}) bool) (b bool) {
	raw.Catch(func() {
		Each(container, func(x interface{}) {
			if f(x) {
				if b {
					b = false
					raw.Throw()
				} else {
					b = true
				}
			}
		})
	})
	return
}