unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: swedebugia <swedebugia@riseup.net>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Help with map match
Date: Fri, 30 Nov 2018 03:45:17 +0100	[thread overview]
Message-ID: <87ftvj2shu.fsf@elephly.net> (raw)
In-Reply-To: <6608cd4f-b96a-c8cb-4cc6-d3c0bb080f94@riseup.net>


Hi,

> I want the procedure to return #t if a match is found and I want it to
> match if it begins with the same e.g. "rollup-plugin" should match
> "rollup-plugin-node-resolve" and return #t
> Else #f

> This did not work:
> (use-modules (ice-9 match))
>
> (define x
>         '("ts" "test"))
> (map (match x
>         ("test") #t)
>         (else #f) x)

“map” requires a procedure and a list as its arguments, applies the
procedure to every element and then returns a new list with the results.

Since you just want a single boolean as the return value you may want to
use “any” instead, which tells you if a procedure returned #t for “any”
of the items in a list.

--8<---------------cut here---------------start------------->8---
(use-modules (srfi srfi-1))

(define (blacklisted? pkg-name)
  (string-prefix? "rollup-" pkg-name))

(any blacklisted?
 '("rollup-plugin" "rollup-plugin-foo")) ; => #t

(any blacklisted?
 '("all" "is" "good")) ; => #f
--8<---------------cut here---------------end--------------->8---

“blacklisted?” can then implement whatever logic you need.

--
Ricardo

  reply	other threads:[~2018-11-30  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 23:13 Help with map match swedebugia
2018-11-30  2:45 ` Ricardo Wurmus [this message]
2018-11-30 13:34 ` Adam Van Ymeren
2018-11-30 13:36   ` Adam Van Ymeren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftvj2shu.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=guix-devel@gnu.org \
    --cc=swedebugia@riseup.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).