Commits

Dobrosław Żybort committed 81dd4f8

Remove list error ErrRange (Go'll panic if index >= len(list), default Go behaviour)

  • Participants
  • Parent commits 53aa97d

Comments (0)

Files changed (2)

 }
 
 var (
-	// ErrRange is returned when index is bigger than list length
-	ErrRange = errors.New("Index out of range")
 	// ErrRemoveFromEmptyList is returned when user want to remove element
 	// from empty list
 	ErrRemoveFromEmptyList = errors.
-				New("Trying to remove element from empty list")
+		New("Trying to remove element from empty list")
 )
 
 //=============================================================================
 	}
 
 	listLen := len(*list)
-	if index >= listLen {
-		return ErrRange
-	}
 
 	copy((*list)[index:], (*list)[index+1:])
 	(*list)[listLen-1] = nil
 		return nil, ErrRemoveFromEmptyList
 	}
 
-	listLen := len(*list)
-	if index >= listLen {
-		return nil, ErrRange
-	}
 	val := (*list)[index]
-
 	(*list).Delete(index)
 
 	return val, nil
 }{
 	{List{"one", "two", "three"}, 1, List{"one", "three"}, nil},
 	{List{"one"}, 0, List{}, nil},
-	{List{"one"}, 1, List{"one"}, ErrRange},
 	{List{}, 0, List{}, ErrRemoveFromEmptyList},
 }