Whoopsies (aka semantic intent)

I caught myself about to make a mistake:

$t = tryCarbonPostMeta(“options”, $p->ID)
->bind(function(Lst $l) {
return $l->filter(function(array $k) {
return $k[‘price’] !== ”;


This content originally appeared on DEV Community and was authored by lray138

I caught myself about to make a mistake:

  $t = tryCarbonPostMeta("options", $p->ID)
                ->bind(function(Lst $l) {
                    return $l->filter(function(array $k) {
                        return $k['price'] !== '';
                    })
                    ->tryHead();
                })
                ->bind(function(Kvm $options) use ($p) {
                    dump($options);
                    die;
                    return tryPartial("/site/menu-item-priced-options.php", [
                        "post" => $p
                    ]);
                });

tryHead did allow me a valid way to use bind here, but I realized, I was locking myself into one option.

blah blah blah

the finished chain looks like this:

return tryCarbonPostMeta("options", $p->ID)
                ->bind(function(Lst $l) use ($data) {
                    return $l->filter(function(array $k) {
                        return $k['price'] !== '';
                    })
                    ->pipe(function(Lst $l) use ($data) {
                        return $l->tryHead()
                            ->fold(function() use ($data) {
                                return tryPartial("/site/partials/menu-item.php", $data);
                            }, function(Kvm $x) use ($data, &$l){
                                return tryPartial("/site/partials/menu-item-priced-options.php", wrap($data)
                                    ->tap(function($x) use (&$l) {
                                        if($x->prop('price')->get() !== '') {
                                            $l = $l->unshift([
                                                'description' => $x->prop('desc')->get(),
                                                'price' => $x->prop('price')->get()
                                            ]);
                                        }
                                        return $x;
                                    })
                                    ->set('optionsHtml', 
                                        $l->map(fn($x) => tryPartial("/site/partials/item-option.php", $x)->getOrElse(Str::of('')))
                                        ->join(tryPartial("/site/partials/or-line.php", [])->getOrElse(Str::of('')))
                                    )->get()

                                );
                            });
                    });
                })
                ->getOrElse(Str::of(''))
                ;

I would say this chunk would be the end of the line of the functional journey I started many years ago...

culminating in tap vs. pipe, map vs bind, etc...

weeeee.....


This content originally appeared on DEV Community and was authored by lray138


Print Share Comment Cite Upload Translate Updates
APA

lray138 | Sciencx (2026-04-19T15:53:06+00:00) Whoopsies (aka semantic intent). Retrieved from https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/

MLA
" » Whoopsies (aka semantic intent)." lray138 | Sciencx - Sunday April 19, 2026, https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/
HARVARD
lray138 | Sciencx Sunday April 19, 2026 » Whoopsies (aka semantic intent)., viewed ,<https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/>
VANCOUVER
lray138 | Sciencx - » Whoopsies (aka semantic intent). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/
CHICAGO
" » Whoopsies (aka semantic intent)." lray138 | Sciencx - Accessed . https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/
IEEE
" » Whoopsies (aka semantic intent)." lray138 | Sciencx [Online]. Available: https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/. [Accessed: ]
rf:citation
» Whoopsies (aka semantic intent) | lray138 | Sciencx | https://www.scien.cx/2026/04/19/whoopsies-aka-semantic-intent/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.