r/functionalprogramming • u/No-Condition8771 • Jun 15 '24
Intro to FP Dear FP, today
Dear FP,
Today I was today years old when I wrote my first ever currying function. I feel...euphoric? Emotional? I want to cry with joy? I wish I could explain this to a random stranger or my gf...
I've been doing web programming for 20 years, mostly procedural and OOP, and only really really got into FP a month or two ago. Heard currying a million times. Read it recently a dozen times. Didn't make sense, just seemed overcomplicated. Not today.
I did a non curryied version (of course) of some test state validation I'm doing, and then I want to use array_map, which in PHP only passes one argument to the callable. And then and there that forced the issue. It's like I can hear the bird singing outside right now.
I know this is not Rust, or Haskell. But I'm happy now.
Thank you for this subreddit.
View all comments
Show parent comment
2
u/No-Condition8771 Jun 16 '24
I'd be nice, if it wasn't PHP. The thing with
array_mapis that it only acceptscallablesas the first argument.That is, it doesn't accept the result of call as in
$assertCase(m\Just::class), only$assertCase,"assertCase", or the array syntax for callables.So no matter how the arguments are juggled around, a closure is going to be required if I want to finesse the parameters passed to the
callable.I could totally do
But then that means that every case I'm testing in the
callablewould be asserting the same type.