-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
40 lines (37 loc) · 1.33 KB
/
Copy pathft_lstmap.c
File metadata and controls
40 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: halhashm <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/23 21:03:02 by halhashm #+# #+# */
/* Updated: 2021/10/23 21:03:05 by halhashm ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *bonus;
t_list *dublist;
t_list *dubrez;
if (!lst || !f)
return (NULL);
dublist = lst;
bonus = NULL;
while (dublist)
{
if (f(dublist->content))
{
dubrez = ft_lstnew(f(dublist->content));
if (!dubrez)
{
ft_lstclear(&bonus, del);
return (NULL);
}
ft_lstadd_back(&bonus, dubrez);
}
dublist = dublist->next;
}
return (bonus);
}