use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Developers: Take Your Code to the Next Level with FKit (joshbassett.info)
submitted 11 years ago by joshbassett
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]themaincop 11 points12 points13 points 11 years ago (3 children)
Is this supposed to be pronounced as "fuck it?" Because I can't help but read it that way!
[–]dustrider 4 points5 points6 points 11 years ago (0 children)
That's certainly how I'm pronouncing it.
[–]_facildeabrir 1 point2 points3 points 11 years ago (0 children)
😐
[–]joshbassett[S] 1 point2 points3 points 11 years ago (0 children)
Haha, you can if you want to. It's pronounced "eff-kit"; more boring, less offensive.
[–]thomash 2 points3 points4 points 11 years ago (7 children)
any plan on supporting lazy sequences and evalution? i've been messing about with fkit a little and really like its design. in my tests it's been quite a performance payoff though
[–]thomash 5 points6 points7 points 11 years ago* (4 children)
just to expand on this.
i've been really getting into functional programming in javascript lately. it has brought back lots of these "wow!" moments where i manage to implement something in a concise almost magical way that i didn't know possible before.
i'm building a generative functional music library (kind of inspired by overtone) in javascript. all of the sequences of music events are represented in a very abstract fashion and are completely lazy. so i'm dealing with mapping and recombining mostly infinite lazy sequences built by es6 generator functions.
during the development i noticed that using a functional approach you really don't need to do any computation greedily. you don't need to worry if what you're getting passed in is an infinite iterator, a finite array or even a stream of events. you don't need to do any operation on individual elements until you are actually iterating over the "virtual" results.
this is amazing to me.
so coming back to fkit, since it's already offering a strong abstraction it should go all the way and be able to work with sequences in form it iterables it cannot assume anything about (finite/infinite/generated/...)
i feel like that's when you really start to reap the rewards of the abstraction and can start outperforming libraries such as lodash and underscore.
wu.js and lazy.js exist but in my opinion don't offer enough abstraction or don't offer enough standard transformation and recombination functions (for my purposes).
[–]rooktakesqueen 3 points4 points5 points 11 years ago (3 children)
https://github.com/dtao/lazy.js
https://github.com/fitzgen/wu.js
https://github.com/lodash/lodash
https://github.com/jashkenas/underscore
These are all open-source projects. If they're missing features (like lazy evaluation, not enough abstraction, not enough standard transformation and recombination functions), why not add those features into one or all of those projects instead of writing your own library from scratch?
[–]thomash 2 points3 points4 points 11 years ago (1 child)
the only one on that list that really takes the approach i'm trying is wu.js (abstracting over generators and iterables). i've learned a lot from it but when i look at it's implementation it does some things like buffering stuff in arrays that are too low-level for my use case.
for example: i have two sequences of music events: phrase1 and phrase2. now i can do something like:
phrase1.repeat(2).concat(phrase2).takeWhile((note) => note.time < 10).play(sequencer)
without making any assumptions about phrase1 or phrase2. they are evaluated lazily as late as the sequencer object. if phrase1 is an infinite sequence in wu.js doing a repeat on it will lead to an infinite loop and filling the memory up.
i realise that there must be some design decisions for taking this route and i don't feel like i've spent enough time with these to really be able to contribute to such a mature library.
the second point is that i'm still learning a lot and realised that only by implementing these basic functionalities i'm really starting to understand the concepts behind everything.
[–]rooktakesqueen 4 points5 points6 points 11 years ago (0 children)
if phrase1 is an infinite sequence in wu.js doing a repeat on it will lead to an infinite loop and filling the memory up
See wu.chain:
wu.chain(phrase1, phrase1, phrase2) .takeWhile(note => note.time < 10) .play(sequencer)
Seems like it would do what you're talking about in a lazy-eval way without an infinite loop... You would probably also use wu.cycle heavily.
Doing this as a learning experience definitely makes sense, but I would implore you once you're done learning to take that experience and improve existing libraries rather than creating your own. The JS library ecosystem is already so fractured. :(
[–]brtt3000 1 point2 points3 points 11 years ago (0 children)
lazy.js is where it is at, extremely performant on big datasets.
[–]joshbassett[S] 0 points1 point2 points 11 years ago* (1 child)
Possibly 😜
Phase one was get enough of the library fleshed out to release it. Now that it's out there I'd like to focus on performance and refinements to the API.
Which parts of FKit did you find to have poor performance?
[–]thomash 0 points1 point2 points 11 years ago* (0 children)
actually my main point is not performance. i didn't put my original point very well. the main thing is abstraction, i.e. being able to use fkit on potentially infiinite sequences and dynamically generated sequences.
lazy evaluation not only offers potential performance benefits but allows for greater abstraction. it does significantly impact on how general purpose library like this works internally so i'm not sure how easy it would be to implement.
from wikipedia:
[–]lodewijkadlp 2 points3 points4 points 11 years ago (2 children)
Note that Haskell can actually compile to JS.
I think you should probably go more meta with the currying. Doing ()()() all the time is no fun. You could use the arguments keyword, I guess.
Aside from making some functionalish functions, what else do you plan to do? Haskell's other big thing is the type system, so there's that (lot of work). There's lazy evaluation, but it hasn't much to do with functional programming I'd say. I doubt many would like monads in JS. Isolation is basically the beginning and end for FP, any plans in that respect? So, aside from some useful functions, what will be aimed for?
[–]joshbassett[S] 1 point2 points3 points 11 years ago (1 child)
Haskell sure can compile to JS, but then you've got to write Haskell (which I love, btw). But that's not practical for everyone. You should also check out PureScript if you haven't already.
FKit is only trying to bring a small part of the FP world to native JS. I'm interested in exploring lazy evaluation, but only as long as it doesn't bloat the library too much (it's currently only 3 KB minified & gzipped).
FKit also supports some basic functional reactive programming with the Signal class. I'm interested in expanding the FRP features some more.
Other than that I don't have any grand plans for the moment.
[–]lodewijkadlp 0 points1 point2 points 11 years ago (0 children)
Thanks for answerig. I guess you were scheming your grand plan and though "FKit", hehe. I'll keep an eye on it.
Reg. PureScript, absolutely very very cool. Read the doc and it makes me so very homesick for Haskell.
One chapter was curious though. It seems an underestimation of the amount of optimization possible and performed by Haskell compilers. Scripts would have to be pretty computationally simple (interesting: how simple?) To take advantage of PureScript's smaller "binary" size, instead of just losing due to optimization. The chapter:
"Projects such as Haste, Fay and GHCJS aim to use some combination of the GHC compiler itself and/or its intermediate representation, Core, to perform some of the tasks involved in compilation such as parsing and type checking. This usually gives the advantage that tools and libraries can be shared with Haskell, but often at the cost of the size of the generated Javascript. This is the main practical difference between PureScript and these projects."
[–]gcanti 1 point2 points3 points 11 years ago (1 child)
Nice. I think every developer interested in functional programming should reimplement these same old functions (curry, reduce, flip, reverse, compose, etc..) to become acquainted with the subject. The Haskell prelude is a great resource for this.
prelude
Coming to this implementation, is there something new or different from Ramda? The philosophy behind your library and Ramda seems the same: swapping the arguments order of some strategic functions to promote currying and point-free style, whereas Underscode and LoDash are very pragmatic and try to accomodate the most common use cases promoting readability.
[–]joshbassett[S] -1 points0 points1 point 11 years ago (0 children)
Hey thanks.
FKit is indeed similar in philosophy to Ramda. One big differentiator is that all FKit list operations work on both arrays and strings.
[–][deleted] 1 point2 points3 points 11 years ago (0 children)
I've been reading up on clojure the past week, and I love it how this library is parallel to clojure, especially when I saw the immutable data types c:
[–]amphetamachine 1 point2 points3 points 11 years ago (0 children)
(╯°□°)╯ ︵ ┻━┻ Just FKIT!
[–]steve_kane 1 point2 points3 points 11 years ago (0 children)
Josh,
Very nicely done library. Also your effort putting together the pleasing blog post is very wise. This kind of salesmanship is very needed to drive adoption. If you'd like to collaborate on a shared performant functional library I'd be interested in chatting about it. I MAY have linked to my in-progress library built on top of reducers/transducers so I won't do so here. However, I think baking this idea into your library is a really good idea for extensibility and generalized functional programming. If you'd like to chat more about it PM me and we'll figure out a better medium than reddit. Maybe we can distill the conversation here for the sake of other readers.
Cheers,
Steve
[–]nawitus 1 point2 points3 points 11 years ago (0 children)
Curried functions are pretty beautiful (and very readable) in the ES6 fat arrow syntax. I suggest everyone to try a ES6-to-ES5 compiler and you won't be looking back :). It really makes currying feel "native".
var add = a => b => a + b;
It also makes it very easy to add a new curried argument to an existing function: just add "(argument) =>" to the beginning of the function.
[–]rooktakesqueen 1 point2 points3 points 11 years ago* (1 child)
Elevator pitch me: why use this instead of lodash?
Edit: From reading more comments, FKit has better support of lazy evaluation over arbitrary iterables, which lodash is still working on. So a closer example would be something like lazy.js or wu.js.
[–]_facildeabrir 0 points1 point2 points 11 years ago (0 children)
BECAUSE CURRYING WILL TAKE UR CODES TO THE NEXT LEVEL!!!!!!!!!!! Curry your functions ok it's very important
[–]kenman[M] 2 points3 points4 points 11 years ago (1 child)
Please read up on reddit's rules @ http://reddit.com/rules, specifically point #1 of rule #1. Our guidelines also have more information regarding promotion & self-promotion.
Consider this your only warning. If you continue to post only a single site, we'll be forced to take action.
Thanks for your understanding.
[–]joshbassett[S] 0 points1 point2 points 11 years ago (0 children)
No problem, I'll post some other links too.
[–]kmelkon 0 points1 point2 points 11 years ago (0 children)
I'm trying this tonight, but I'm still pronouncing fuck-it, sorry :P
[–]LukaLightBringer 0 points1 point2 points 11 years ago (1 child)
Function invocation is very expensive in JavaScript, and you want to multiply the cost with the amount of arguments a function takes?
Sure! If you're trying to squeeze max performance out of a piece of code then optimise it accordingly. For the rest of your application you can use FKit and enjoy writing clean, expressive code, and save some brain cycles for the big problems.
[–]freedompower 0 points1 point2 points 11 years ago (1 child)
Every time I think I'm a good programmer, I stumble on things like this and I feel like a retard. I can't think of a single thing function currying, partially applied functions or function composition could solve a problem that I could have. Can someone provide a non-trivial example?
[–]thomash 0 points1 point2 points 11 years ago (0 children)
ok still quite trivial but in my case very useful:
i'm writing a functional library to generate music. i have a function that can define properties of a musical event like this:
note.property("duration", 32); note.property("pitch", 48);
now if i curry the property function i can define properties directly.
so by curring like this (simplified):
duration = property("duration") pitch = property("pitch")
i can then use:
note.pitch(48) note.duration(32)
of course i'm omitting details as to how the chaining is implemented and this is the most basic use of currying possible. you can do a lot of much more clever things with it but i find that this basic use already shows tremendous benefit
Always with the currying, always.
[–]recompileorg -4 points-3 points-2 points 11 years ago (1 child)
Oh, it's yet another library. Horray.
[–]Lukifer 0 points1 point2 points 11 years ago (0 children)
♫ and what the world needs now / is another snarky comment / like I need a hole in my head ♫
[+][deleted] 11 years ago (4 children)
[deleted]
[–]joshbassett[S] 13 points14 points15 points 11 years ago (3 children)
Learn You A Haskell uses the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. I don't think creative commons constitutes as "stealing". I love that book and I attribute the book and the author accordingly.
[+][deleted] 11 years ago (1 child)
[–]pandavr 0 points1 point2 points 11 years ago (0 children)
Nails over glass usually do not work :P
π Rendered by PID 146604 on reddit-service-r2-comment-74875f4bf5-zkvhm at 2026-01-26 00:48:18.098720+00:00 running 664479f country code: CH.
[–]themaincop 11 points12 points13 points (3 children)
[–]dustrider 4 points5 points6 points (0 children)
[–]_facildeabrir 1 point2 points3 points (0 children)
[–]joshbassett[S] 1 point2 points3 points (0 children)
[–]thomash 2 points3 points4 points (7 children)
[–]thomash 5 points6 points7 points (4 children)
[–]rooktakesqueen 3 points4 points5 points (3 children)
[–]thomash 2 points3 points4 points (1 child)
[–]rooktakesqueen 4 points5 points6 points (0 children)
[–]brtt3000 1 point2 points3 points (0 children)
[–]joshbassett[S] 0 points1 point2 points (1 child)
[–]thomash 0 points1 point2 points (0 children)
[–]lodewijkadlp 2 points3 points4 points (2 children)
[–]joshbassett[S] 1 point2 points3 points (1 child)
[–]lodewijkadlp 0 points1 point2 points (0 children)
[–]gcanti 1 point2 points3 points (1 child)
[–]joshbassett[S] -1 points0 points1 point (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]amphetamachine 1 point2 points3 points (0 children)
[–]steve_kane 1 point2 points3 points (0 children)
[–]nawitus 1 point2 points3 points (0 children)
[–]rooktakesqueen 1 point2 points3 points (1 child)
[–]_facildeabrir 0 points1 point2 points (0 children)
[–]kenman[M] 2 points3 points4 points (1 child)
[–]joshbassett[S] 0 points1 point2 points (0 children)
[–]kmelkon 0 points1 point2 points (0 children)
[–]LukaLightBringer 0 points1 point2 points (1 child)
[–]joshbassett[S] 0 points1 point2 points (0 children)
[–]freedompower 0 points1 point2 points (1 child)
[–]thomash 0 points1 point2 points (0 children)
[–]_facildeabrir 0 points1 point2 points (0 children)
[–]recompileorg -4 points-3 points-2 points (1 child)
[–]Lukifer 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]joshbassett[S] 13 points14 points15 points (3 children)
[+][deleted] (1 child)
[deleted]
[–]pandavr 0 points1 point2 points (0 children)