Functional style - examples

I wasn’t looking for this … but when I thought about it for a while, something struck me.

Blog - Žarko Gajić

Quick Algorithm: Display an Array of Integers as Set of Integer Ranges

That whole procedure can be reduced to …

      TArray.Sort<integer>(intArray).Unique;

      Compare ( Array, Array_shifted_by_1 ) -> List < Record  of (start year, or successor) >

      Reduce to Lists of Ranges.

ie :

I think Vincent was writing something like this recently

Yes, 'tho in my head it was kinda the opposite direction … I need to think about it a bit more.

The advantage of composability …

Hey! That might just work!

1 Like

Starting in 40 mins online …

Ben Deane: Applicative: The Forgotten Functional Pattern

Monads get all the press. Functors are often presented as a prerequisite to monads. Applicative (functor) almost never gets mentioned. But it’s massively useful - to the point where a lot of the time when we think about a “monadic interface” what we really want is an applicative interface.

This talk will put applicative in the limelight, showing how it works and why it’s so powerful, with lots of examples grounded in code; there are no category theory diagrams in this talk. Attendees will come away with a solid understanding of the applicative pattern and its many uses. And as a byproduct, their opinions of monads will probably change too.
Optionals. Expected. Ranges. Futures. Parsing. Validation. Error Handling. Transforms. Functions themselves. These are all examples where thinking in terms of applicatives (and importantly, NOT just reaching for “a monadic interface”) helps us write simpler, more composable code. If you’re kind of fuzzy about functors and monads, what’s missing is probably the third piece of the puzzle: applicative.

We will attempt as usual to have a remote / hybrid event.

Checkout this Meetup with Denver C++ Meetup: Ben Deane: Applicative: The Forgotten Functional Pattern, Thu, May 4, 2023, 6:00 PM | Meetup

ITDevcon 2011 - Primož Gabrijelčič - Going functional - part 1/3

ITDevcon 2011 - Primož Gabrijelčič - Going functional - part 2/3

ITDevcon 2011 - Primož Gabrijelčič - Going functional - part 3/3

Hana Dusikova is the author of C++ library CTRE (compile-time regular expressions)

Isaque Pinheiro https://www.linkedin.com/in/isaquepinheirooficialbr/

(Translated to english)
Taking Delphi to the Next Level with Pattern Matching
Delphi has been a robust and powerful programming language for many years, widely adopted by developers. However, as more modern languages such as Rust, F#, Python, and Kotlin have emerged with advanced features such as pattern matching, Delphi developers may have missed this native functionality.

Pattern matching is a valuable technique that allows you to check and extract data from complex structures concisely, improving readability and reducing the need for excessive conditional statements. My recent journey of developing a CLI using languages like C++, Dart, and Rust made me realize the effectiveness of pattern matching in making code clearer and more efficient. However, upon returning to Delphi, where I maintain large projects and many of them open source, I noticed that pattern matching functionality was offered in a limited way in the compiler.

This inspired me to explore ways to bring some of this feature to Delphi, resulting in the creation of the Essential Core Library for Delphi (ECLBr) library. With ECLBr, Delphi developers now have the ability to write leaner, more readable code, which not only makes maintenance easier, but also opens up new development opportunities. This library allows you to create robust and efficient applications in Delphi, combining the power of this language with the clarity of pattern matching.

If you’re ready to take your Delphi development to a new level, you can’t help but consider ECLBr as an essential tool in your toolbox. Hashtags: #delphi #patternmatching #modernlanguages #programming #development

1 Like

International Pascal Conference, Spain. 2023

Keynote speaker: Primož Gabrijelčič
Title: “Parallel programming in Pascal: How we should stop focusing on threads and start writing functional code”

Summary: For many Pascal programmers, the topic of parallel programming starts and stops with “write a thread, run a thread”. There are better ways to approach this problem, as the rest of the world has already noticed, and we should finally accept that we are no longer living in the nineties and that we should start writing parallel code that focuses on solving some problem and not - as many of us do - on solving problems that arise from improper use of the multithreading paradigm.

A nice talk … Balancing OOP & FP

:rofl:

A map (dictionary) of strings to lambda functions.
From : ifcplusplus/IfcPlusPlus/src/ifcpp/IFC4X3/EntityFactory.cpp at master · ifcquery/ifcplusplus · GitHub

static std::map< std::string, std::function<BuildingEntity*( void )> > entity_factory_map = {
{ "IFCACTIONREQUEST",            []()->BuildingEntity* { return new IFC4X3::IfcActionRequest();         } },
{ "IFCACTOR",                    []()->BuildingEntity* { return new IFC4X3::IfcActor();                 } },
{ "IFCACTORROLE",                []()->BuildingEntity* { return new IFC4X3::IfcActorRole();             } },
{ "IFCACTUATOR",                 []()->BuildingEntity* { return new IFC4X3::IfcActuator();              } },
{ "IFCACTUATORTYPE",             []()->BuildingEntity* { return new IFC4X3::IfcActuatorType();          } },
{ "IFCADDRESS",                  []()->BuildingEntity* { return new IFC4X3::IfcAddress();               } },
{ "IFCADVANCEDBREP",             []()->BuildingEntity* { return new IFC4X3::IfcAdvancedBrep();          } },
{ "IFCADVANCEDBREPWITHVOIDS",    []()->BuildingEntity* { return new IFC4X3::IfcAdvancedBrepWithVoids(); } },
{ "IFCADVANCEDFACE",             []()->BuildingEntity* { return new IFC4X3::IfcAdvancedFace();          } },
{ "IFCAIRTERMINAL",              []()->BuildingEntity* { return new IFC4X3::IfcAirTerminal();           } },
{ "IFCAIRTERMINALBOX",           []()->BuildingEntity* { return new IFC4X3::IfcAirTerminalBox();        } },
{ "IFCAIRTERMINALBOXTYPE",       []()->BuildingEntity* { return new IFC4X3::IfcAirTerminalBoxType();    } },
{ "IFCAIRTERMINALTYPE",          []()->BuildingEntity* { return new IFC4X3::IfcAirTerminalType();       } },
{ "IFCAIRTOAIRHEATRECOVERY",     []()->BuildingEntity* { return new IFC4X3::IfcAirToAirHeatRecovery();  } },
{ "IFCAIRTOAIRHEATRECOVERYTYPE", []()->BuildingEntity* { return new IFC4X3::IfcAirToAirHeatRecoveryType(); } },
{ "IFCALARM",                    []()->BuildingEntity* { return new IFC4X3::IfcAlarm();                 } },
...
};

It is a performance driven application …

Not sure if list initialization actually counts as “functional style”.