[Haskell-cafe] 回复： Replace list item with list.
David Lilue
dvdalilue at gmail.com
Sat Nov 4 12:47:03 UTC 2017
There is a function "concatMap" to simplify "concat $ map".
Furthermore, you could use inline notation as follow:
concatMap (\x -> x == "z" then B else [x]) A
On Sat, Nov 4, 2017 at 7:50 AM, Денис Мирзоев <nolane16 at gmail.com> wrote:
> If you sure "z" is the last element of A you can use
>
> init A ++ B
>
> if it's somwhere in the middle consider
>
> cocat $ map f A
> where
> f x
> | x == "z" = B
> | otherwise = [x]
>
> On Sat, Nov 4, 2017 at 2:41 PM, Денис Мирзоев <nolane16 at gmail.com> wrote:
>
>> If you sure "z" is the last element of A you can use
>>
>> init A ++ B
>>
>> if it's somwhere in the middle consider
>>
>> cocat $ map f A
>> where
>> f x
>> | x == "z" = B
>> | otherwise = [x]
>>
>> On Sat, Nov 4, 2017 at 1:57 PM, FlyingSheep <flyingsheep at qq.com> wrote:
>>
>>> (take 2 A) ++ B
>>>
>>> ------------------
>>> 李 鹏
>>> 四川大学计算机学院
>>>
>>>
>>>
>>> ------------------ 原始邮件 ------------------
>>> *发件人:* "mirone"<saul-mirone at qq.com>;
>>> *发送时间:* 2017年11月4日(星期六) 晚上6:48
>>> *收件人:* "haskell-cafe"<haskell-cafe at haskell.org>;
>>> *主题:* [Haskell-cafe] Replace list item with list.
>>>
>>> Hello everyone!
>>> If I have a list A : ["x", "y", "z"]
>>> and a list B: ["f", "g"].
>>> Here is my question:
>>> What's the simplest way to replace "z" in the list A by list B, and get
>>> ["x", "y", "f", "g"] ?
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> Only members subscribed via the mailman list are allowed to post.
>>>
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
ᐧ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171104/ffaa2ba5/attachment.html>
More information about the Haskell-Cafe
mailing list