From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29169 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ilia Zaihcuk Newsgroups: gmane.text.pandoc Subject: Removing parts of the document with [walk] in Haskell Date: Sat, 4 Sep 2021 12:09:28 -0700 (PDT) Message-ID: <915213fc-e4c4-480b-a6a2-fd3420777ddan@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5008_1584712843.1630782568565" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14993"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD6IFBEKVAFBB2MIZ6EQMGQE3Y6MY7I-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Sep 04 21:09:33 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f64.google.com ([209.85.161.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mMb2h-0003fB-Rt for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 04 Sep 2021 21:09:31 +0200 Original-Received: by mail-oo1-f64.google.com with SMTP id a127-20020a4a4c850000b029028b35f322edsf1654852oob.9 for ; Sat, 04 Sep 2021 12:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=N9zF3EJFXCU5aYGceAhCDTCrSJYlX2VonH7d9IgeOQw=; b=Lx2iEiKqtOT3RDJPaK7AbT0f8A2HB5nz5LshA+ZhEhnUuis0LR1zdBfQWxQ50g6+h6 RdprJsTEGXQvZXm292EWhNtl9M5prb8zi9rpv0Y67Pp+x65T8gjFt3Gkr6RPSZZU42RE 7CemOUbjQQ3dSvHq6YAc2hQt26fiC/5u0q7IEjPMfbyfIK2/5JgAX485munhAZ8U0llK b/38Kh0hd3sdxj4bUtUtD0ajQl676ftEHkIhzkOCtzl3IoU2MHsgiAwwICM4uUGc3SO/ 9IQ0uiUtv1t7H0fU94b8nBYXY9YitZDzE28ruPMlFrucXEE8O77plxViqcUq6v48Wt0w 7rkg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:subject:mime-version:x-original-sender :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=N9zF3EJFXCU5aYGceAhCDTCrSJYlX2VonH7d9IgeOQw=; b=nPdQvoXlm3kIDiA3nDbk6EooXUi2kt0txJKZku2ZOL+CBDd35Gle0gMDGiliUjo4Kn sqg85tP6od0gtXAhauwWc3Wtzfx6BN+xriWq4rhrB4xFXstGoY33vWZdewgIWseqUWJA nzjpPHWcIMnwlAK+Hax48+ICBuCtklkgavqTqfj9BEqBh81ZE59NJOM6iOvwSCjque4M kMRtm1fsWNNbcwKJu9dyy9qCrSDbC79sxaVhubC2irGTxyLa577nlPtigFTqE1NxLoGE oq2bryU4Q17DulJDX7FUHLfrfRiePlZ3+svIyTFwgz61iLdov7RiGvXS3JYgYpA9LQeo AfHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=N9zF3EJFXCU5aYGceAhCDTCrSJYlX2VonH7d9IgeOQw=; b=Z7c36TstPKB4ixKZ5Zw3+7kRzIApm7J/oTQPBFC4lRXVSFRjwlpgclhr+tzn/U7VTN edRT85h62jZ3VpjfxmUaeahe6MN8eis47lFSF06wo4KY+38+zTsp9D1LCGcChRJnVHdR nZf/ZbM4gydb4BfPD2ke5tBXAXr7ZJeAXj5GNcqNI+0wIgVvELSfW6h0n8PshQDuDnXH wj3OqLnLV1yp0wcKlJHZEIAMGUnhDUrCsYHAJr+tkVY2pHpus9HMVaRrpwWfZu2gYUF2 ouiKv+qCPcLQ4PaMfMw7Vg6CXH9usfROgbHf3G5IHlg2k49eDdi2nBCrz8ddpCNRxV1M VzgA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM531Qwk0zTVMoTDkIk7kR32Y4TmFhnJiLtEbca4YR44hLoWNvrEa+ qonhLg7ejgJ7CeUUUh5mMe8= X-Google-Smtp-Source: ABdhPJyrLTkGoSd+sJljPDNPi3F1t9osDNR6Gd2rRSJ7oOL06Q8KLD9A8hxIvDSayS2duMIHfV3gag== X-Received: by 2002:a05:6830:608:: with SMTP id w8mr4419876oti.73.1630782570885; Sat, 04 Sep 2021 12:09:30 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:62c9:: with SMTP id z9ls709900otk.6.gmail; Sat, 04 Sep 2021 12:09:29 -0700 (PDT) X-Received: by 2002:a9d:1ae:: with SMTP id e43mr4489838ote.26.1630782569186; Sat, 04 Sep 2021 12:09:29 -0700 (PDT) X-Original-Sender: zoickx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:29169 Archived-At: ------=_Part_5008_1584712843.1630782568565 Content-Type: multipart/alternative; boundary="----=_Part_5009_783136511.1630782568565" ------=_Part_5009_783136511.1630782568565 Content-Type: text/plain; charset="UTF-8" Hi all, Using pandoc-types' Walkable class, what is the best-performing/most idiomatic way to filter out certain elements from a document? Say I wanted to remove all occurrences of the word "the" from a Pandoc. The best implementation I've been able to write for this is isThe :: Inline -> Bool isThe (Str "the") = True isThe _ = False removeThe :: Pandoc -> Pandoc removeThe = walk (filter $ not . isThe) Is this right? Does the use of filter here not mean an additional O(n) traversal happens on every list of Inlines? I feel like a better solution for this would be using filterThe :: Inline -> [Inline] filterThe (Str "the") = [] filterThe x = [x] or something similar, but of course removeThe = walk filterThe does not typecheck. We need a -> a, meaning [Inline] -> [Inline] here. The same question actually applies to any transformation which "changes the number of elements": theFine :: Inline -> [Inline] theFine (Str "the") = [Str "the", Space, Str "fine"] theFine i = [i] allIsFine :: Pandoc -> Pandoc allIsFine = walk $ concatMap theFine Best, Ilia P.S. Sorry if this has been asked before. I feel it must be a common issue, but all I've been able to find is this thread with its links, which are 7 years old now and seem to be calling for changes in pandoc. Everything else suggests stepping outside Haskell. -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/915213fc-e4c4-480b-a6a2-fd3420777ddan%40googlegroups.com. ------=_Part_5009_783136511.1630782568565 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

Using pandoc-types' Walkable class, what is the best-performing/most idioma= tic way to filter out certain elements from a document?

<= /div>
Say I wanted to remove all occurrences of the word "the" from a <= span style=3D"font-family: Courier New;">Pandoc. The best implementa= tion I've been able to write for this is

isThe :: Inline -> Bool
isThe (Str "the") =3D True
isThe _ =3D False

removeThe :: Pandoc -> Pandoc=
removeThe = =3D walk (filter $ not . isThe)

= Is this right? Does the use of fi= lter here not mean an additional O(n) traversal happens on every list of Inlines?

I feel li= ke a better solution for this would be using

filterThe :: Inline -> [Inline]
filterThe (Str "the") =3D []
filterThe x = =3D [x]

or something similar, bu= t of course
<= br>
removeThe = =3D walk filterThe

does not type= check. We need a -> a, = meaning [Inline] -> [Inline] here.


The same question a= ctually applies to any transformation which "changes the number of elements= ":

t= heFine :: Inline -> [Inline]
theFine (Str "the") =3D [Str= "the", Space, Str "fine"]
theFine i =3D [i]
allIsFine :: Pandoc -> Pandoc
allIsFine =3D w= alk $ concatMap theFine

Best,

Ilia

P.S. Sorry if this has been asked before. I fee= l it must be a common issue, but all I've been able to find is thi= s thread with its links, which are 7 years old now and seem to be calli= ng for changes in pandoc. Everything else suggests stepping outside Haskell= .

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/915213fc-e4c4-480b-a6a2-fd3420777ddan%40googlegroups.= com.
------=_Part_5009_783136511.1630782568565-- ------=_Part_5008_1584712843.1630782568565--