From 84778fcd7a246687d91d0e7b3c0dfcd26104f8d6 Mon Sep 17 00:00:00 2001 From: Don Stewart Date: Fri, 24 Nov 2006 01:12:49 +0000 Subject: [PATCH] Add an example of the use of unfoldr, following doc feedback from dozer --- Data/List.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Data/List.hs b/Data/List.hs index 2ce489d..b6a847b 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -855,7 +855,12 @@ rqpart cmp x (y:ys) rle rgt r = -- -- > f' (f x y) = Just (x,y) -- > f' z = Nothing - +-- +-- A simple use of unfoldr: +-- +-- > unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10 +-- > [10,9,8,7,6,5,4,3,2,1] +-- unfoldr :: (b -> Maybe (a, b)) -> b -> [a] unfoldr f b = case f b of -- 1.7.10.4