<div dir="auto">Yes, a custom-built fold would be a little faster in general, and significantly faster if the range only included a few elements. The challenge is that there are lots of such functions we could add, and it's not clear which would pay for their API clutter. Someone might want any combination of including and excluding each endpoint, with (at least) all the methods of Foldable and also a monomorphic traverse-like function.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 15, 2020, 7:21 AM Compl Yue via Haskell-Cafe <<a href="mailto:haskell-cafe@haskell.org">haskell-cafe@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div>
    <p>Hello,</p>
    <p>I have a question regarding 'Data.Map' api, filed an issue  <a href="https://github.com/haskell/containers/issues/708" target="_blank" rel="noreferrer">https://github.com/haskell/containers/issues/708</a></p>
    <p>And may be I can ask here at the same time?</p>
    <p style="box-sizing:border-box;margin-top:0px!important;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">I'm not sure why<span> </span><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:11.9px;padding:0.2em 0.4em;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Data.Map</code><span> </span>doesn't
      have a key range based visiting API, I figured out I can do it
      this way:</p>
    <pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:11.9px;margin-top:0px;margin-bottom:16px;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;color:rgb(36,41,46);font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:11.9px;padding:0px;margin:0px;background:initial;border-radius:3px;word-break:normal;white-space:pre-wrap;border:0px;display:inline;overflow:visible;line-height:inherit">indexKeyRange
  :: IndexKey -> IndexKey -> Map IndexKey Object -> [(IndexKey, Object)]
indexKeyRange !minKey !maxKey =
  toList
    . takeWhileAntitone (<= maxKey)
    . dropWhileAntitone (< minKey)
</code></pre>
    <p>But wouldn't it save the
      computation needed to re-balance the intermediate tree generated ?
      Or that re-balancing can be optimized out actually ?</p>
    <p>I am creating an
      in-memory graph database, using<span> </span><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:11.9px;padding:0.2em 0.4em;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Data.Map.Strict.Map</code><span> </span>as
      business object indices with specified object attributes. The
      typical scenario will be querying a small number of entries by key
      range, out of possibly all business objects of a certain class
      globally, so the implementation above would work, but not
      reasonable by far as it seems.</p>
    <p style="box-sizing:border-box;margin-top:0px;margin-bottom:0px!important;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">I think a lazy list
      returned by mere node visiting (i.e. no new node creation) would
      satisfy my needs, or I missed something ?</p>
    <p style="box-sizing:border-box;margin-top:0px;margin-bottom:0px!important;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br>
    </p>
    <p>Thanks,</p>
    <p>Compl</p>
    <p><br>
    </p>
  </div>

_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>