libft_old/extended_libft/ft_lstmap.c
Willem Haffmans 326f52308e all
2024-07-26 22:32:04 +02:00

36 lines
1013 B
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 18:42:06 by whaffman #+# #+# */
/* Updated: 2024/07/10 17:21:58 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_list;
t_list *new_elem;
if (!lst || !f)
return (NULL);
new_list = NULL;
while (lst)
{
new_elem = ft_lstnew(f(lst->content));
if (!new_elem)
{
ft_lstclear(&new_list, del);
return (NULL);
}
ft_lstadd_back(&new_list, new_elem);
lst = lst->next;
}
return (new_list);
}