我想知道如何将列表合并为一个大列表。例如
让我们说我们得到一个结构,
(define-struct fruits (type number))
基本上给出了这个
(list
(list (make-fruits 'Apple 4) (make-fruits 'Orange 3) (make-fruits 'Pears 5))
(list (make-fruits 'Peach 4))
(list (make-fruits 'Kiwi 5) (make-fruits 'Banana 2)))
如何将所有这些列表结构合并为一个大列表?使用local,map,foldr,filter和不使用递归的任何方式。
答案 0 :(得分:0)
#lang racket
(define-struct fruits (type number) #:transparent)
(apply append
(list
(list (make-fruits 'Apple 4) (make-fruits 'Orange 3) (make-fruits 'Pears 5))
(list (make-fruits 'Peach 4))
(list (make-fruits 'Kiwi 5) (make-fruits 'Banana 2))))
结果:
(list (fruits 'Apple 4) (fruits 'Orange 3) (fruits 'Pears 5) (fruits 'Peach 4) (fruits 'Kiwi 5) (fruits 'Banana 2))