So, I have a function f that takes a string as input. I want to create a function g that maps f to a vector of strings. Ie
g 'Hello' 'world'
should yield
(f 'Hello')(f 'world')
Here's what I did:
g ← {f¨⍵}
And this works just fine for the example above. However, it doesn't work when the right argument is just one string, as it maps f to every character of that string. For example:
g 'Hello'
yields
(f 'H')(f 'e')(f 'l')(f 'l')(f 'o')
Of course, I wanted the output to be f 'Hello'
.
I could write
g ← {f¨⊂⍵}
So that 'Hello'
would be interpreted as
┌─────┐
│Hello│
└─────┘
But then 'Hello' 'world'
will be interpreted as
┌─────────────┐
│┌─────┬─────┐│
││Hello│world││
│└─────┴─────┘│
└─────────────┘
And then it won't map correctly.
Is there a way to solve this succinctly?
You're looking for ⊆
⊆'hello'
┌─────┐
│hello│
└─────┘
⊆'hello' 'world'
┌─────┬─────┐
│hello│world│
└─────┴─────┘
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.