aboutsummaryrefslogtreecommitdiff
path: root/ft_lstmap_bonus.c
blob: 4cb195f5f836376f1cc029e1dd740822ddfb569b (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_lstmap_bonus.c                                  :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/10/09 09:03:57 by cacharle          #+#    #+#             */
/*   Updated: 2019/10/09 09:09:13 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include "libft_bonus.h"

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);
	}
	return (mapped);
}