18
1
Let us say that we have a particular set of functions on strings. These functions are kind of like fill in the blanks or madlibs, except that they only take one input and use that to fill in all of their blanks. For example we might have a function that looks like
I went to the ____ store and bought ____ today.
If we applied this function to the string cheese
the result would be:
I went to the cheese store and bought cheese today.
We can represent these functions as a non-empty list of strings, where the blanks are simply the gaps in between strings. For example our function above would be:
["I went to the ", " store and bought ", " today."]
With this representation there is only one representation for every function of this sort and only one function for each representation.
A really neat thing is that the set of such functions is closed under composition. That is to say composition of two of our functions is always another one of these functions. For example if I compose our function above with
["blue ", ""]
(the function that prepends blue
to the input)
We get the function:
["I went to the blue ", " store and bought blue ", " today."]
These can get a little more complex though. For example if we compose the first function with
["big ", " and ", ""]
The result is
["I went to the big ", " and ", " store and bought big ", "and", " today."]
Task
Your task is to take two functions as described as non-empty lists of strings and output their composition as a non-empty list of strings.
For the purpose of this challenge a list can be any ordered container that permits duplicates and a string may be a native string type, a list of characters or a list of integers.
This is code-golf answers will be scored in bytes with fewer bytes being better.
Test cases
["","xy"] ["ab",""] -> ["ab","xy"]
["x","y","z"] ["a","b"] -> ["xa","bya","bz"]
["xy"] ["ab"] -> ["xy"]
["","",""] ["a",""] -> ["a","a",""]
["x",""] ["","",""] -> ["x","",""]
["x","y","z"] ["a","b","c"] -> ["xa","b","cya","b","cz"]
["x","x","x"] ["a"] -> ["xaxax"]
["w","x","y","z"] ["ab","cd","e"] -> ["wab","cd","exab","cd","eyab","cd","ez"]
1All 3 existing answers currently fail if some non-printable ASCII character is used in the input (SOH, TAB or LF, depending on the answer). So I think you should really decide if the input is restricted to printable ASCII or not. – Arnauld – 2019-07-29T15:51:20.187
@Arnauld Ok well as of now it is unrestricted and I have not seen a reason to change that so it will remain. – Post Rock Garf Hunter – 2019-07-29T15:57:50.760
@SriotchilismO'Zaic In that case all six current answers are invalid. – Kevin Cruijssen – 2019-07-29T16:54:27.740
2@KevinCruijssen mine's valid since zero is not a character. Lucky language feature helping out. – Jonathan Allan – 2019-07-29T16:56:07.020
@JonathanAllan Ah, I thought Jelly had mixed types so
"0"
and0
would be the same, my bad. The other five are invalid, though. – Kevin Cruijssen – 2019-07-29T16:58:11.737@KevinCruijssen I do not know C#, 05AB1E, perl 5, or Javascript well enough to verify the answers are incorrect or what they are doing but I have informed flawr that the Haskell answer has this issue. – Post Rock Garf Hunter – 2019-07-29T17:00:59.590
1@SriotchilismO'Zaic My 05AB1E was joining/splitting by newlines. The JavaScript and Haskell answers are joining/splitting by tabs, the C# answer by the unprintable character `` (SOH), so those are all invalid as well. I don't know Perl 5 well enough either, though. So that one might be valid. – Kevin Cruijssen – 2019-07-29T17:03:52.023
Does "unrestricted" refer to the ASCII range 1..127 or to the byte range 1..255? In other words, can we use non-ASCII characters in the range 128..255 as separators that will be guaranteed never to occur in the input strings? – Roman – 2019-07-30T11:54:31.333
3@Roman You cannot assume that any character will not appear in the input so that you may use it as a separator. You must actually solve the challenge. – Post Rock Garf Hunter – 2019-07-30T13:07:24.037