fractol/libft/src/ft_lstmap.c

41 lines
1.3 KiB
C
Raw Normal View History

2023-03-01 04:36:42 +01:00
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/13 19:30:13 by djonker #+# #+# */
/* Updated: 2023/02/07 00:40:34 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
void *s;
t_list *r;
t_list *t;
r = NULL;
t = NULL;
while (lst)
{
if (f(lst->content))
{
s = f(lst->content);
t = ft_lstnew(s);
if (!(t))
{
ft_lstclear(&r, del);
lst = NULL;
return (NULL);
}
ft_lstadd_back(&r, t);
}
lst = lst->next;
}
return (r);
}