mirror of
https://github.com/Ladebeze66/libft.git
synced 2025-12-13 04:36:55 +01:00
36 lines
1.2 KiB
C
Executable File
36 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstmap.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
|
{
|
|
t_list *tmp;
|
|
t_list *res;
|
|
|
|
if (!lst || !f)
|
|
return (NULL);
|
|
res = 0;
|
|
while (lst)
|
|
{
|
|
tmp = ft_lstnew((*f)(lst->content));
|
|
if (!tmp)
|
|
{
|
|
ft_lstclear(&res, del);
|
|
return (NULL);
|
|
}
|
|
ft_lstadd_back(&res, tmp);
|
|
lst = lst->next;
|
|
}
|
|
return (res);
|
|
}
|