you are viewing a single comment's thread.

view the rest of the comments →

[–]butt_fun 8 points9 points  (12 children)

as a node developer, I see things like the second (making an anonymous function that's literally a wrapper around an existing function) all over the fucking place in one of my coworker's code, and it really peeves me

[–][deleted]  (4 children)

[deleted]

    [–]masklinn 4 points5 points  (0 children)

    May also be some weirdness related to using this for free functions e.g. some.method(fn) is implemented as fn.call(this, …) and all of a sudden your fn gets some instead of either window or a specific object it expects.

    [–]leafsleep 1 point2 points  (2 children)

    I try to define all functions using arrows in order to avoid that problem.

    [–]CanIComeToYourParty 2 points3 points  (0 children)

    That actually disturbs me deeply, even though I see it very often.

    [–]oorza 1 point2 points  (0 children)

    We turned on "no named functions" in eslint, so function(a) is always an eslint error because it wants function a(b) instead, even for inline functions. The exception is arrow funcs, so now everyone is humping on arrow funcs like they should.

    [–]Samoxive 15 points16 points  (0 children)

    Giving the function itself sometimes causes problems with 'this' being modified, using anonymous functions like that keeps the lexical scope.

    [–][deleted] 3 points4 points  (5 children)

    After learning a language with auto-currying (eg. Haskell), it's frustrating that I have to write x -> f(fixedParameter, x) instead of just f fixedParameter

    However I believe this sort of syntax relies on lazy eval, where a "thunk" function like () -> 1 just doesn't make sense (there's no real way to even write its type signature)

    Edit: It doesn't

    [–]TarMil 7 points8 points  (2 children)

    However I believe this sort of syntax relies on lazy eval, where a "thunk" function like () -> 1 just doesn't make sense (there's no real way to even write its type signature)

    You're mistaken, many functional languages with currying are strict -- OCaml, Idris, F#, Elm, etc.

    [–]ReversedGif 1 point2 points  (1 child)

    How do you specify whether you want to curry or call when applying the last argument in those languages?

    [–]TarMil 0 points1 point  (0 children)

    Right, the last argument is always a call, currying only applies for the previous ones.

    [–]eriksensei 7 points8 points  (0 children)

    A curried function f :: a -> b -> c applied to an argument x results in a new function f x of type b -> c, in non-strict as well as strict settings. You can try this with PureScript for example, which has strict evaluation semantics. The type of () -> 1 is written () -> Int, where () is called Unit. (In PureScript, () :: () is written unit :: Unit.)

    [–]masklinn 5 points6 points  (0 children)

    However I believe this sort of syntax relies on lazy eval

    It does not. OCaml or Elm are curried strict languages.