aboutsummaryrefslogtreecommitdiff
path: root/ft_lstmap_bonus.c
diff options
context:
space:
mode:
authorCabergs Charles <cacharle@e-r5-p7.s19.be>2019-10-09 17:00:48 +0200
committerCabergs Charles <cacharle@e-r5-p7.s19.be>2019-10-09 17:00:48 +0200
commit84409d8d3fa8bd9bae28b3523aa6d0c0b3a68406 (patch)
treea41cbc8c6a3a4f52309dea94a0fdf3c688804124 /ft_lstmap_bonus.c
parent840957aee277e7c426647cc133b2a41e7cecd9a9 (diff)
downloadlibft-84409d8d3fa8bd9bae28b3523aa6d0c0b3a68406.tar.gz
libft-84409d8d3fa8bd9bae28b3523aa6d0c0b3a68406.tar.bz2
libft-84409d8d3fa8bd9bae28b3523aa6d0c0b3a68406.zip
Small update
Diffstat (limited to 'ft_lstmap_bonus.c')
-rw-r--r--ft_lstmap_bonus.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/ft_lstmap_bonus.c b/ft_lstmap_bonus.c
index 4cb195f..3a0247a 100644
--- a/ft_lstmap_bonus.c
+++ b/ft_lstmap_bonus.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/09 09:03:57 by cacharle #+# #+# */
-/* Updated: 2019/10/09 09:09:13 by cacharle ### ########.fr */
+/* Updated: 2019/10/09 12:41:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,14 +16,11 @@
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *))
{
t_list *mapped;
- t_list *tmp;
- while (lst != NULL)
- {
- tmp = ft_lstnew(lst->content);
- tmp->next = lst->next;
- tmp = (*f)(tmp);
- ft_lstadd_back(&mapped, tmp);
- }
+ if (lst == NULL)
+ return (NULL);
+ if ((mapped = ft_lstnew(lst->content)) == NULL)
+ return (NULL);
+ mapped->next = ft_lstmap(lst->next, f);
return (mapped);
}