dev4py.utils.lists
1# Copyright 2022 the original author or authors (i.e.: St4rG00se for Dev4py). 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from typing import Any 16 17from dev4py.utils.objects import require_non_none 18from dev4py.utils.types import T 19 20 21def empty_list() -> list[Any]: 22 """ 23 Returns an empty list 24 25 Returns: 26 list[Any]: An empty list 27 """ 28 return [] 29 30 31def append(lst: list[T], value: T) -> list[T]: 32 """ 33 Adds the given value to the given list and returns the list 34 35 Args: 36 lst: the list 37 value: the value to add 38 39 Returns: 40 list[T]: The list with the added value 41 42 Raises: 43 TypeError: if the list is None 44 """ 45 require_non_none(lst).append(value) 46 return lst 47 48 49def extend(lst_1: list[T], lst_2: list[T]) -> list[T]: 50 """ 51 Adds all values from the second list to the first one and returns it 52 53 Args: 54 lst_1: The list where to add elements 55 lst_2: The list with the elements to add 56 57 Returns: 58 lst_1 (list[T]): The first list with added elements 59 60 Raises: 61 TypeError: if lst_1 or lst_2 is None 62 """ 63 require_non_none(lst_1).extend(require_non_none(lst_2)) 64 return lst_1
def
empty_list() -> list[typing.Any]:
22def empty_list() -> list[Any]: 23 """ 24 Returns an empty list 25 26 Returns: 27 list[Any]: An empty list 28 """ 29 return []
Returns an empty list
Returns:
list[Any]: An empty list
def
append(lst: list[~T], value: ~T) -> list[~T]:
32def append(lst: list[T], value: T) -> list[T]: 33 """ 34 Adds the given value to the given list and returns the list 35 36 Args: 37 lst: the list 38 value: the value to add 39 40 Returns: 41 list[T]: The list with the added value 42 43 Raises: 44 TypeError: if the list is None 45 """ 46 require_non_none(lst).append(value) 47 return lst
Adds the given value to the given list and returns the list
Arguments:
- lst: the list
- value: the value to add
Returns:
list[T]: The list with the added value
Raises:
- TypeError: if the list is None
def
extend(lst_1: list[~T], lst_2: list[~T]) -> list[~T]:
50def extend(lst_1: list[T], lst_2: list[T]) -> list[T]: 51 """ 52 Adds all values from the second list to the first one and returns it 53 54 Args: 55 lst_1: The list where to add elements 56 lst_2: The list with the elements to add 57 58 Returns: 59 lst_1 (list[T]): The first list with added elements 60 61 Raises: 62 TypeError: if lst_1 or lst_2 is None 63 """ 64 require_non_none(lst_1).extend(require_non_none(lst_2)) 65 return lst_1
Adds all values from the second list to the first one and returns it
Arguments:
- lst_1: The list where to add elements
- lst_2: The list with the elements to add
Returns:
lst_1 (list[T]): The first list with added elements
Raises:
- TypeError: if lst_1 or lst_2 is None