<jupyter_start><jupyter_text>Lasagna & Recursion  The first layer<jupyter_code>from discopy import Ty, Id, Box

lasagna, ragu, sheet, sheets = map(Ty, 'lasagna ragu sheet sheets'.split())

stack = Box('STACK', sheet @ lasagna, lasagna)
take = Box('TAKE', ragu, ragu @ ragu)
spread = Box('SPREAD', lasagna @ ragu, lasagna)

lasagna_layer = stack @ take >> spread @ Id(ragu)
lasagna_layer.draw()<jupyter_output><empty_output><jupyter_text>The next layer with a functor<jupyter_code>from discopy import Functor

start = Box('KEEP ON GOING!', sheets @ lasagna @ ragu, lasagna)

Next = Functor(
    ob=lambda x:
        sheets @ sheet if x == sheets else x,
    ar=lambda f:
        Id(sheets) @ lasagna_layer >> start
        if f == start else f)

two_layers = Next(Next(start))
two_layers.draw()<jupyter_output><empty_output><jupyter_text>The complete recipe<jupyter_code>store = Box("STORE", ragu, Ty())

Stop = Functor(
    ob=lambda x: Ty() if x == sheets else x,
    ar=lambda f: Id(lasagna) @ store if f == start else f)

complete_recipe = start
for _ in range(3):
    complete_recipe = Next(complete_recipe)
complete_recipe = Stop(complete_recipe)

complete_recipe.draw()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12448132780082988, 'fraction_numerical': 0.0008298755186721991, 'mean_word_length': 4.940886699507389, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '113319', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 437, 'n_tokens_neox': 434, 'n_words': 114, 'path': 'docs/notebooks/lasagna-recursion.ipynb', 'repo_name': 'edenian/discopy', 'size': '1205'}