Module Prelude::List
In: lib/prelude/list.rb

$Id: list.rb 17 2006-09-17 18:03:15Z prelude $

This eventually needs to be implemented with lazy lists, see lazylist.rubyforge.org for details

I used the signatures of Haskell’s List.hs file in order not to forget to implement the functions defined there and to remind of what was intended.

Methods

all   and_   any   break_   concat   concatMap   concat_map   cycle   delete   drop   dropWhile   drop_while   elem   elemIndex   elemIndices   elem_index   elem_indices   filter   find   findIndex   findIndices   find_index   find_indices   foldl   foldl1   foldl1_   foldl_   foldr   foldr1   group   head   init   inits   insert   intersect   intersperse   isPrefixOf   isSuffixOf   is_prefix_of   is_suffix_of   iterate   last   length   lines   lookup   map   mapAccumL   mapAccumR   map_accum_l   map_accum_r   maximum   minimum   notElem   not_elem   nub   null   or_   partition   product   repeat   replicate   reverse   scanl   scanl1   scanr   scanr1   sort   span   split_at   sum   tail   tails   take   takeWhile   take_while   transpose   unfoldr   union   unlines   unwords   unzip   unzip3   unzip4   words   zip   zip3   zip4   zipWith   zipWith3   zipWith4   zip_with   zip_with3   zip_with4  

Public Instance methods

all — :(a -> Bool) -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 180
180:     def all(f, list)
181:       and_(~map(f, list))
182:     end
and — :[Bool] -> Bool

[Source]

     # File lib/prelude/list.rb, line 165
165:     def and_(list)
166:       foldr(lambda {|x,y| x && y}, true, list)
167:     end
any — :(a -> Bool) -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 175
175:     def any(f, list)
176:       or_(~map(f, list))
177:     end
break — :(a -> Bool) -> [a] -> ([a], [a])

[Source]

     # File lib/prelude/list.rb, line 333
333:     def break_(list)
334:       warn "Method 'break' is not implemented yet." if $VERBOSE
335:       return lambda { [] }
336:     end
concat — :[[a]] -> [a]

[Source]

     # File lib/prelude/list.rb, line 153
153:     def concat(list)
154:       foldr(-:+, [], list)
155:     end
concatMap(list)

Alias for concat_map

concatMap — :(a -> [b]) -> [a] -> [b]

[Source]

     # File lib/prelude/list.rb, line 158
158:     def concat_map(list)
159:       warn "Method 'concatMap' is not implemented yet." if $VERBOSE
160:       return lambda { [] }
161:     end
cycle — :[a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 275
275:     def cycle(list)
276:       warn "Method 'cycle' is not implemented yet." if $VERBOSE
277:       return lambda { [] }
278:     end
delete — :(Eq a) => a -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 555
555:     def delete(o, list)
556:       warn "Method 'delete' is not implemented yet." if $VERBOSE
557:       return lambda { [] }
558:     end
drop — :Int -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 298
298:     def drop(n, list)
299:       lambda { list[n..-1] }
300:     end
dropWhile(p, list)

Alias for drop_while

dropWhile — :(a -> Bool) -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 318
318:     def drop_while(p, list)
319:       case list
320:       when [] : lambda { [] }
321:       else      p[~head(list)] ? lambda { ~drop_while(p, ~tail(list)) } : lambda { list }
322:       end
323:     end
elem — :a -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 379
379:     def elem(list)
380:       warn "Method 'elem' is not implemented yet." if $VERBOSE
381:       return lambda { [] }
382:     end
elemIndex(list)

Alias for elem_index

elemIndices(list)

Alias for elem_indices

elemIndex — :(Eq a) => a -> [a] -> Maybe Int

[Source]

     # File lib/prelude/list.rb, line 425
425:     def elem_index(list)
426:       warn "Method 'elem_index' is not implemented yet." if $VERBOSE
427:       return lambda { [] }
428:     end
elemIndices — :(Eq a) => a -> [a] -> [Int]

[Source]

     # File lib/prelude/list.rb, line 433
433:     def elem_indices(list)
434:       warn "Method 'elem_indices' is not implemented yet." if $VERBOSE
435:       return lambda { [] }
436:     end
filter — :(a -> Bool) -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 407
407:     def filter(list)
408:       warn "Method 'filter' is not implemented yet." if $VERBOSE
409:       return lambda { [] }
410:     end
find — :(a -> Bool) -> [a] -> Maybe a

[Source]

     # File lib/prelude/list.rb, line 401
401:     def find(p, list)
402:       warn "Method 'find' is not implemented yet." if $VERBOSE
403:       return lambda { [] }
404:     end
findIndex(list)

Alias for find_index

findIndices(list)

Alias for find_indices

findIndex — :(a -> Bool) -> [a] -> Maybe Int

[Source]

     # File lib/prelude/list.rb, line 441
441:     def find_index(list)
442:       warn "Method 'find_index' is not implemented yet." if $VERBOSE
443:       return lambda { [] }
444:     end
findIndices — :(a -> Bool) -> [a] -> [Int]

[Source]

     # File lib/prelude/list.rb, line 449
449:     def find_indices(list)
450:       warn "Method 'find_indices' is not implemented yet." if $VERBOSE
451:       return lambda { [] }
452:     end
foldl — :(a -> b -> a) -> a -> [b] -> a

[Source]

     # File lib/prelude/list.rb, line 113
113:     def foldl(f, a, list)
114:       case list
115:       when [] : lambda { a }
116:       else      lambda { f[~foldl(f, a, ~tail(list)), ~head(list)] }
117:       end
118:     end
foldl1 — :(a -> a -> a) -> [a] -> a

[Source]

     # File lib/prelude/list.rb, line 127
127:     def foldl1(f, list)
128:       foldl(f, ~head(list), ~tail(list))
129:     end
foldl1’ — :(a -> a -> a) -> [a] -> a

[Source]

     # File lib/prelude/list.rb, line 132
132:     def foldl1_(list)
133:       warn "Method 'foldl1_' is not implemented yet." if $VERBOSE
134:       return lambda { [] }
135:     end
foldl’ — :(a -> b -> a) -> a -> [b] -> a

[Source]

     # File lib/prelude/list.rb, line 121
121:     def foldl_(list)
122:       warn "Method 'foldl_' is not implemented yet." if $VERBOSE
123:       return lambda { [] }
124:     end
foldr — :(a -> b -> b) -> b -> [a] -> b

[Source]

     # File lib/prelude/list.rb, line 138
138:     def foldr(f, s, list)
139:       case list
140:       when [] : lambda { s }
141:       else      lambda { f[~head(list), ~foldr(f, s, ~tail(list))] }
142:       end
143:     end
foldr1 — :(a -> a -> a) -> [a] -> a

[Source]

     # File lib/prelude/list.rb, line 146
146:     def foldr1(f, list)
147:       foldr(f, ~head(list), ~tail(list))
148:     end
group — :Eq a => [a] -> [[a]]

[Source]

     # File lib/prelude/list.rb, line 339
339:     def group(list)
340:       warn "Method 'group' is not implemented yet." if $VERBOSE
341:       return lambda { [] }
342:     end
head — :[a] -> a

[Source]

    # File lib/prelude/list.rb, line 36
36:     def head(list)
37:       case list
38:       when [] : empty_list_error
39:       else      lambda { list[0] }
40:       end
41:     end
init — :[a] -> [a]

[Source]

    # File lib/prelude/list.rb, line 61
61:     def init(list)
62:       case list
63:       when []        : empty_list_error
64:       when [list[0]] : lambda { [] }
65:       else             lambda { [~head(list)]+~init(~tail(list)) }
66:       end
67:     end
inits — :[a] -> [[a]]

[Source]

     # File lib/prelude/list.rb, line 345
345:     def inits(list)
346:       warn "Method 'inits' is not implemented yet." if $VERBOSE
347:       return lambda { [] }
348:     end
insert — :(Ord a) => a -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 581
581:     def insert(o, list)
582:       warn "Method 'insert' is not implemented yet." if $VERBOSE
583:       return lambda { [] }
584:     end
intersect — :(Eq a) => [a] -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 567
567:     def intersect(list)
568:       warn "Method 'intersect' is not implemented yet." if $VERBOSE
569:       return lambda { [] }
570:     end
intersperse — :a -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 99
 99:     def intersperse(list)
100:       warn "Method 'intersperse' is not implemented yet." if $VERBOSE
101:       return lambda { [] }
102:     end
isPrefixOf(list)

Alias for is_prefix_of

isSuffixOf(list)

Alias for is_suffix_of

isPrefixOf — :(Eq a) => [a] -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 359
359:     def is_prefix_of(list)
360:       warn "Method 'is_prefix_of' is not implemented yet." if $VERBOSE
361:       return lambda { [] }
362:     end
isSuffixOf — :(Eq a) => [a] -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 367
367:     def is_suffix_of(list)
368:       warn "Method 'is_suffix_of' is not implemented yet." if $VERBOSE
369:       return lambda { [] }
370:     end
iterate — :(a -> a) -> a -> [a]

[Source]

     # File lib/prelude/list.rb, line 257
257:     def iterate(list)
258:       warn "Method 'iterate' is not implemented yet." if $VERBOSE
259:       return lambda { [] }
260:     end
last — :[a] -> a

[Source]

    # File lib/prelude/list.rb, line 52
52:     def last(list)
53:       case list
54:       when []        : empty_list_error
55:       when [list[0]] : lambda { list[0] }
56:       else             last(~tail(list))
57:       end
58:     end
length — :[a] -> Int

[Source]

    # File lib/prelude/list.rb, line 75
75:     def length(list)
76:       lambda { list.length }
77:     end
lines — :String -> [String]

[Source]

     # File lib/prelude/list.rb, line 523
523:     def lines(list)
524:       warn "Method 'lines' is not implemented yet." if $VERBOSE
525:       return lambda { [] }
526:     end
lookup — :(Eq a) => a -> [(a,b)] -> Maybe b

[Source]

     # File lib/prelude/list.rb, line 393
393:     def lookup(list)
394:       warn "Method 'lookup' is not implemented yet." if $VERBOSE
395:       return lambda { [] }
396:     end
map — :(a -> b) -> [a] -> [b]

[Source]

    # File lib/prelude/list.rb, line 80
80:     def map(f, list)
81:       case list
82:       when [] : lambda{ [] }
83:       else      lambda{ [ f[~head(list)] ] + ~map(f, ~tail(list)) }
84:       end
85:     end
mapAccumL(list)

Alias for map_accum_l

mapAccumR(list)

Alias for map_accum_r

mapAccumL — :(a -> b -> (a,c)) -> a -> [b] -> (a,[c])

[Source]

     # File lib/prelude/list.rb, line 239
239:     def map_accum_l(list)
240:       warn "Method 'map_accum_l' is not implemented yet." if $VERBOSE
241:       return lambda { [] }
242:     end
mapAccumR — :(a -> b -> (a,c)) -> a -> [b] -> (a,[c])

[Source]

     # File lib/prelude/list.rb, line 247
247:     def map_accum_r(list)
248:       warn "Method 'map_accum_r' is not implemented yet." if $VERBOSE
249:       return lambda { [] }
250:     end
maximum — :(Ord a) => [a] -> a

[Source]

     # File lib/prelude/list.rb, line 197
197:     def maximum(list)
198:       warn "Method 'maximum' is not implemented yet." if $VERBOSE
199:       return lambda { [] }
200:     end
minimum — :(Ord a) => [a] -> a

[Source]

     # File lib/prelude/list.rb, line 203
203:     def minimum(list)
204:       warn "Method 'minimum' is not implemented yet." if $VERBOSE
205:       return lambda { [] }
206:     end
notElem(list)

Alias for not_elem

notElem — :a -> [a] -> Bool

[Source]

     # File lib/prelude/list.rb, line 385
385:     def not_elem(list)
386:       warn "Method 'not_elem' is not implemented yet." if $VERBOSE
387:       return lambda { [] }
388:     end
nub — :(Eq a) => [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 549
549:     def nub(list)
550:       warn "Method 'nub' is not implemented yet." if $VERBOSE
551:       return lambda { [] }
552:     end
null — :[a] -> Bool

[Source]

    # File lib/prelude/list.rb, line 70
70:     def null(list)
71:       lambda { list.size == 0 }
72:     end
or — :[Bool] -> Bool

[Source]

     # File lib/prelude/list.rb, line 170
170:     def or_(list)
171:       foldr(lambda {|x,y| (x || y)}, false, list)
172:     end
partition — :(a -> Bool) -> [a] -> ([a], [a])

[Source]

     # File lib/prelude/list.rb, line 413
413:     def partition(p, list)
414:       warn "Method 'partition' is not implemented yet." if $VERBOSE
415:       return lambda { [] }
416:     end
product — :(Num a) => [a] -> a

[Source]

     # File lib/prelude/list.rb, line 191
191:     def product(list)
192:       warn "Method 'product' is not implemented yet." if $VERBOSE
193:       return lambda { [] }
194:     end
repeat — :a -> [a]

[Source]

     # File lib/prelude/list.rb, line 263
263:     def repeat(list)
264:       warn "Method 'repeat' is not implemented yet." if $VERBOSE
265:       return lambda { [] }
266:     end
replicate — :Int -> a -> [a]

[Source]

     # File lib/prelude/list.rb, line 269
269:     def replicate(list)
270:       warn "Method 'replicate' is not implemented yet." if $VERBOSE
271:       return lambda { [] }
272:     end
, reverse — :[a] -> [a]

[Source]

    # File lib/prelude/list.rb, line 88
88:     def reverse(list)
89:       r = proc { |l, a|
90:         case l
91:         when [] : lambda { a }
92:         else      lambda { ~r[~tail(l), [~head(l)]+a] }
93:         end
94:       }
95:       r[list, []]
96:     end
scanl — :(a -> b -> a) -> a -> [b] -> [a]

[Source]

     # File lib/prelude/list.rb, line 213
213:     def scanl(f, s, list)
214:       warn "Method 'scanl' is not implemented yet." if $VERBOSE
215:       return lambda { [] }
216:     end
scanl1 — :(a -> a -> a) -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 219
219:     def scanl1(f, list)
220:       warn "Method 'scanl1' is not implemented yet." if $VERBOSE
221:       return lambda { [] }
222:     end
scanr — :(a -> b -> b) -> b -> [a] -> [b]

[Source]

     # File lib/prelude/list.rb, line 225
225:     def scanr(f, s, list)
226:       warn "Method 'scanr' is not implemented yet." if $VERBOSE
227:       return lambda { [] }
228:     end
scanr1 — :(a -> a -> a) -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 231
231:     def scanr1(f, list)
232:       warn "Method 'scanr1' is not implemented yet." if $VERBOSE
233:       return lambda { [] }
234:     end
sort — :(Ord a) => [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 575
575:     def sort(list)
576:       warn "Method 'sort' is not implemented yet." if $VERBOSE
577:       return lambda { [] }
578:     end
span — :(a -> Bool) -> [a] -> ([a], [a])

[Source]

     # File lib/prelude/list.rb, line 328
328:     def span(p, list)
329:       lambda { [~takeWhile(p, list), ~dropWhile(p,list)] }
330:     end
splitAt — :Int -> [a] -> ([a], [a])

[Source]

     # File lib/prelude/list.rb, line 303
303:     def split_at(n, list)
304:       lambda { [~take(n, list), ~drop(n, list)] }
305:     end
sum — :(Num a) => [a] -> a

[Source]

     # File lib/prelude/list.rb, line 185
185:     def sum(list)
186:       warn "Method 'sum' is not implemented yet." if $VERBOSE
187:       return lambda { [] }
188:     end
tail — :[a] -> [a]

[Source]

    # File lib/prelude/list.rb, line 44
44:     def tail(list)
45:       case list
46:       when [] : empty_list_error
47:       else      lambda { list[1..-1] }
48:       end
49:     end
tails — :[a] -> [[a]]

[Source]

     # File lib/prelude/list.rb, line 351
351:     def tails(list)
352:       warn "Method 'tails' is not implemented yet." if $VERBOSE
353:       return lambda { [] }
354:     end
take — :Int -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 293
293:     def take(n, list)
294:       lambda { list[0..(n-1)] }
295:     end
takeWhile(p, list)

Alias for take_while

takeWhile — :(a -> Bool) -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 308
308:     def take_while(p, list)
309:       case list
310:       when [] : lambda { [] }
311:       else      p[~head(list)] ? lambda { [~head(list)]+ ~take_while(p, ~tail(list)) } : lambda { [] }
312:       end
313:     end
transpose — :[[a]] -> [[a]]

[Source]

     # File lib/prelude/list.rb, line 105
105:     def transpose(list)
106:       # FIXIT
107:       lambda { list.transpose }
108:     end
unfoldr — :(b -> Maybe (a, b)) -> b -> [a]

[Source]

     # File lib/prelude/list.rb, line 283
283:     def unfoldr(list)
284:       warn "Method 'unfoldr' is not implemented yet." if $VERBOSE
285:       return lambda { [] }
286:     end
union — :(Eq a) => [a] -> [a] -> [a]

[Source]

     # File lib/prelude/list.rb, line 561
561:     def union(list)
562:       warn "Method 'union' is not implemented yet." if $VERBOSE
563:       return lambda { [] }
564:     end
unlines — :[String] -> String

[Source]

     # File lib/prelude/list.rb, line 535
535:     def unlines(list)
536:       warn "Method 'unlines' is not implemented yet." if $VERBOSE
537:       return lambda { [] }
538:     end
unwords — :[String] -> String

[Source]

     # File lib/prelude/list.rb, line 541
541:     def unwords(list)
542:       warn "Method 'unwords' is not implemented yet." if $VERBOSE
543:       return lambda { [] }
544:     end
unzip — :[(a,b)] -> ([a],[b])

[Source]

     # File lib/prelude/list.rb, line 501
501:     def unzip(list)
502:       warn "Method 'unzip' is not implemented yet." if $VERBOSE
503:       return lambda { [] }
504:     end

unzip3

[Source]

     # File lib/prelude/list.rb, line 507
507:     def unzip3(list)
508:       warn "Method 'unzip3' is not implemented yet." if $VERBOSE
509:       return lambda { [] }
510:     end

unzip4, unzip5, unzip6, unzip7

[Source]

     # File lib/prelude/list.rb, line 513
513:     def unzip4(list)
514:       warn "Method 'unzip4' is not implemented yet." if $VERBOSE
515:       return lambda { [] }
516:     end
words — :String -> [String]

[Source]

     # File lib/prelude/list.rb, line 529
529:     def words(list)
530:       warn "Method 'words' is not implemented yet." if $VERBOSE
531:       return lambda { [] }
532:     end
zip — :[a] -> [b] -> [(a,b)]

[Source]

     # File lib/prelude/list.rb, line 459
459:     def zip(list1, list2)
460:       warn "Method 'zip' is not implemented yet." if $VERBOSE
461:       return lambda { [] }
462:     end

zip3

[Source]

     # File lib/prelude/list.rb, line 465
465:     def zip3(list)
466:       warn "Method 'zip3' is not implemented yet." if $VERBOSE
467:       return lambda { [] }
468:     end

zip4, zip5, zip6, zip7

[Source]

     # File lib/prelude/list.rb, line 471
471:     def zip4(list)
472:       warn "Method 'zip4' is not implemented yet." if $VERBOSE
473:       return lambda { [] }
474:     end
zipWith(list)

Alias for zip_with

zipWith3(list)

Alias for zip_with3

zipWith4(list)

Alias for zip_with4

zipWith — :(a -> b -> c) -> [a] -> [b] -> [c]

[Source]

     # File lib/prelude/list.rb, line 477
477:     def zip_with(list)
478:       warn "Method 'zip_with' is not implemented yet." if $VERBOSE
479:       return lambda { [] }
480:     end

zipWith3

[Source]

     # File lib/prelude/list.rb, line 485
485:     def zip_with3(list)
486:       warn "Method 'zip_with3' is not implemented yet." if $VERBOSE
487:       return lambda { [] }
488:     end

zipWith4, zipWith5, zipWith6, zipWith7

[Source]

     # File lib/prelude/list.rb, line 493
493:     def zip_with4(list)
494:       warn "Method 'zip_with4' is not implemented yet." if $VERBOSE
495:       return lambda { [] }
496:     end