These are chat archives for ramda/ramda
headOr :: a -> [a] -> afunction which returns the first argument for an empty list?
R.ifElse(R.identity, fn, null);
maybebe confused with
Maybe(a)monad fantasyland style?
maybeis like poor man's
Maybein small scale and in my opinion have ended up in solutions that were more elegant than otherwise would've been.
+both concatenates strings and adds numbers.
That's a strawman. No one is suggestion that every conceivable value should be wrapped in maybe.
R.ifElse(R.isNil, R.identity, fn)will return the result of the function call if the value is not null. Otherwise you will still have null..
R.ifElse(R.isNil, R.identity)could work as a kind of "poor mans maybe". Pass a function to it and you will have a null check version of that function. Where
Nothingthis will safely keep returning null to you.
yes. but if we entertain the idea that i'm not quite ready wrapping my values in
Maybe (just yet ;)) ... then i do have a lot of NPE-avoiding code. off the top of my head, i often write stuff like:
b = some?.deep?.fun?(a) b.map(something) if b
R.ifElse(R.isNil, R.identity)to aviod the need for
R.ifElsegoes into useful bits of code.
S.fromMaybe('default', S.gets(['deep', 'fun'], some).ap(a).map(something))
this transducer blog post. stuff like
into(to, xform, from) it says
apply xform to each value in the collection from and append it to the collection to
doesn't this make fp-people cringe?
I think years of programming with a simple type system like most of the ALGOL based languages (C/C#/Java/etc) have will do that to anyone.
Years of programming with a better type system like the ISWIM based languages (ML/Haskell/PureScript/etc) have will generally do the opposite.
Maybewith their optionals, but it's so painful. it's absolutely impossible to use any API without the incessant control compilation-as-you-type of their dev environment. well. I like emacs. i still haven't seen a way of doing strong typing with a big API like cocoa or java.lang, without the need of a special editor.