string-map(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’– string-map πŸ’–

okay so this is from the Scheme Programmer's Manual, section 3scm, and it's literally about mapping a procedure over characters in strings. bestie, it's giving functional realness. πŸ¦‹

✨ NAME ✨

string-map β€” map a procedure over the characters in strings.

πŸŽ€ LIBRARY πŸŽ€

(import (scheme base))              ;R7RS

🌸 SYNOPSIS 🌸

(string-map proc string1 string2 ...)

πŸ’… DESCRIPTION πŸ’…

string-map takes proc and applies it element-wise to the elements of the strings, then returns a string of the results, in order. no cap. ✨

If you give it more than one string and not all strings have the same length, string-map terminates when the shortest string runs out. short queen behavior, honestly. πŸ‘‘

The dynamic order in which proc is applied to the elements of the strings is unspecified. so don't assume an order, bestie.

If multiple returns occur from string-map, the values returned by earlier returns are not mutated. that's the rule. πŸ’œ

🫢 RETURN VALUES 🫢

Returns a single string object. one string, that's it. πŸ’–

πŸ”₯ EXAMPLES πŸ”₯

here's the receipts, fr fr:

(string-map char-foldcase "AbdEgH")
        => "abdegh"

(string-map
 (lambda (c)
   (integer->char (+ 1 (char->integer c))))
 "HAL")
        => "IBM"

; Demonstrates how it ends on the shortest string
(string-map
 (lambda (c k)
   ((if (eqv? k #) char-upcase char-downcase)
    c))
 "studlycaps xxx"
 "ululululul")
        => "StUdLyCaPs"

πŸ’€ ERRORS πŸ’€

bestie, these are errors, not cute little suggestions:
  • It is an error if proc does not accept as many arguments as there are strings or does not return a single character.
  • It is likewise an error if there are fewer than two arguments or if one of the arguments is outside its domain.
  • Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. 😭

🌈 SEE ALSO 🌈

map(3scm) β€” go check that one out too. iykyk. πŸ‘‘

⭐ STANDARDS ⭐

R7RS β€” periodt. πŸ’…

πŸ¦‹ HISTORY πŸ¦‹

This procedure also appears in SRFI-13. iconic crossover. ✨

πŸ“ AUTHORS πŸ“

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


mwah πŸ’‹ this page is dated 2022-03-29 and the footer tag is string-map(3scm), so that's the source/version + date sign-off, bestie. 🫢

πŸ“¦ where this page comes from