Technology Apr 23, 2026 · 2 min read

Never Say Final.. ha.. the last.. or...

$class_names = wrap($data) ->tryProp('page_config') ->bind(function (Lst $x) { return $x->filter(function ($y) { return $y['_type'] === 'header'; }) ->tryHead(); }) ->bind(function ($x) {...

DE
DEV Community
by lray138
Never Say Final.. ha.. the last.. or...
$class_names = wrap($data)
        ->tryProp('page_config')
        ->bind(function (Lst $x) {
            return $x->filter(function ($y) {
                return $y['_type'] === 'header';
            })
                ->tryHead();
        })
        ->bind(function ($x) {
            return $x->tryProp('header_attrs');
        })
        ->bind(function ($x) {
            return $x->filter(function ($y) {
                return $y['_type'] === 'class';
            })
                ->tryHead();
        })
        ->bind(function ($x) {
            return $x->tryProp('class');
        })
        ->getOrElse('');

This is the repeating pattern:

->tryProp('page_config')
        ->bind(function (Lst $x) {
            return $x->filter(function ($y) {
                return $y['_type'] === 'header';
            })
                ->tryHead();
        })

after we create and apply a a prop equals function we have this:

->bind(fn (Lst $x) 
            => $x->filter(propEquals('_type', 'header'))
                ->tryHead())

well, this intrduced the rabbit hole and you can spend yyears trying to find the right way, then AI comes in and it's a whole new ballgame...

    $class_names = wrap($data)
        ->tryProp('page_config')
        ->bind(fn(Lst $x) => $x->filter(propEquals('_type', 'header'))->tryHead())
        ->bind(fn(Kvm $x) => $x->tryProp('header_attrs'))
        ->bind(fn(Lst $x) => $x->filter(propEquals('_type', 'class'))->tryHead())
        ->bind(fn(Kvm $x) => $x->tryProp('class'))
        ->getOrElse('');

I would settle on something like this he above for now... and would lean toward ... you get to the crux with the "tryHead"

DE
Source

This article was originally published by DEV Community and written by lray138.

Read original article on DEV Community
Back to Discover

Reading List