{"_id":"Katy","_rev":"11-d407d9a52efd3001117cd729532db1f5","name":"Katy","description":"CoffeeScript Combinators","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.4":{"author":{"name":"Reg Braithwaite","email":"raganwald@gmail.com","url":"http://reginald.braythwayt.com"},"name":"Katy","description":"Fluent Coffeescript","version":"0.0.4","homepage":"https://github.com/raganwald/Katy","repository":{"type":"git","url":"git://github.com/raganwald/Katy.git"},"main":"lib/katy.js","scripts":{"test":"jasmine-node --coffee --verbose spec"},"engines":{"node":"*"},"dependencies":{},"devDependencies":{},"_npmUser":{"name":"raganwald","email":"raganwald@gmail.com"},"_id":"Katy@0.0.4","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"fec8e7c9d88eed7ba7814380c2130b92580242f9","tarball":"https://registry.npmjs.org/Katy/-/Katy-0.0.4.tgz","integrity":"sha512-nXUbAxpTsMM7wbuIKxGjVrOHTDsJhtshFsUamT6LhwaL8yIOWqPeIrN3rIgYBooTsr4n3LuXDeStG7yhU66DZA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEin+kyf+9G+3j+lAXs7Eo/nrDO7YNGyVsQ53gagUxHEAiEAz9B+A1onKlRvxCZ/DpAW7GW20GCUtBRVyDgYNmf13aQ="}]},"maintainers":[{"name":"raganwald","email":"raganwald@gmail.com"}]},"0.0.5":{"author":{"name":"Reg Braithwaite","email":"raganwald@gmail.com","url":"http://reginald.braythwayt.com"},"name":"Katy","description":"CoffeeScript Combinators","version":"0.0.5","homepage":"https://github.com/raganwald/Katy","repository":{"type":"git","url":"git://github.com/raganwald/Katy.git"},"main":"lib/katy.js","scripts":{"test":"jasmine-node --coffee --verbose spec"},"engines":{"node":"*"},"dependencies":{},"devDependencies":{},"_npmUser":{"name":"raganwald","email":"raganwald@gmail.com"},"_id":"Katy@0.0.5","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"aafd4f113e480b9f3efd3604d800ea5a8b6c3f7f","tarball":"https://registry.npmjs.org/Katy/-/Katy-0.0.5.tgz","integrity":"sha512-86bQwUVrUXm5rX0MRC1gwnRSS98UQNTyvOHOVdoDGiefp69KdSTidDpdLFQYGSEMjQY9yVcm65I1EfSoccn4OQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDb4OmYAh7miKhMgwcO1LNeoVsRy43Qhdv3g1GDjSxZ9AIhAKgsO1MmxSavS67M/8Hxx55lNro2J5Cm6lvp6xnI2Ju6"}]},"maintainers":[{"name":"raganwald","email":"raganwald@gmail.com"}]},"0.0.6":{"author":{"name":"Reg Braithwaite","email":"raganwald@gmail.com","url":"http://reginald.braythwayt.com"},"name":"Katy","description":"CoffeeScript Combinators","version":"0.0.6","homepage":"https://github.com/raganwald/Katy","repository":{"type":"git","url":"git://github.com/raganwald/Katy.git"},"main":"lib/katy.js","scripts":{"test":"jasmine-node --coffee --verbose spec"},"engines":{"node":"*"},"dependencies":{},"devDependencies":{},"_npmUser":{"name":"raganwald","email":"raganwald@gmail.com"},"_id":"Katy@0.0.6","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"eafbfd8f2164ad6da91fefa91aa774c274e227fb","tarball":"https://registry.npmjs.org/Katy/-/Katy-0.0.6.tgz","integrity":"sha512-fj7XKxOh8/el2uVjvQYud4HNCviFqHTRW26TFNkmgyi6eqvCyEmZaQ/ZK0yHD7Grh7U5flBkjlc/wLwpEsAqVw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHjlEVLbX0tIL9OunsMdd7KidAhj2B1Ba/wHZllBMJ1PAiAz/Bj8a16ISm5qG4A90jHKpSarH+jUMhM5WK7FvTJ+qA=="}]},"maintainers":[{"name":"raganwald","email":"raganwald@gmail.com"}]},"1.0.0":{"author":{"name":"Reg Braithwaite","email":"raganwald@gmail.com","url":"http://reginald.braythwayt.com"},"name":"Katy","description":"CoffeeScript Combinators","version":"1.0.0","homepage":"https://github.com/raganwald/Katy","repository":{"type":"git","url":"git://github.com/raganwald/Katy.git"},"main":"lib/katy.js","scripts":{"test":"jasmine-node --coffee --verbose spec"},"engines":{"node":"*"},"dependencies":{},"devDependencies":{},"_npmUser":{"name":"raganwald","email":"raganwald@gmail.com"},"_id":"Katy@1.0.0","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"8f71053110b43438728e7fc474f8c12e2891ca0a","tarball":"https://registry.npmjs.org/Katy/-/Katy-1.0.0.tgz","integrity":"sha512-uG57RZuDlL+Sr0hk4RMPDdTR3kI3Gl1V+Dss4yCFjdFZq2ot9AoitchsVy/jc56eo3zDr3HNrMIhJ3KUOnXnkQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0jZvks4rsiG0aCfiv5FHehWdibfvTbjgtlIhT5bzNZwIgTqe+PeL5XkG70+/uu00RpTUyJrSQk5eoEl+sryN8NJM="}]},"maintainers":[{"name":"raganwald","email":"raganwald@gmail.com"}]}},"readme":"Katy: Coffeescript Combinators\n===\n\nKaty makes writing [fluent][fluent] Coffeescript easy by providing the `.K` and `.T` combinators for Coffeescript objects.\n\nThe **tl;dr** is that Katy adds two methods, `.K` and `.T` to any class or classes you desire:\n\n```coffeescript\nKT = require('Katy').KT\n\nKT.mixInto(String)\n\n# K calls a function on the receiver and returns the receiver\n\n'Hello'.K (s) -> s + ' World'\n  # => returns 'Hello'\n  \n# T calls a function on the receiver and returns the result\n\n'Hello'.K (s) -> s + ' World'\n  # => returns 'Hello World'\n```\n\nYou can also call any method by name:\n\n```coffeescript\nKT.mixInto(Array)\n\n[1..10]\n  .K('pop')\n  .K('pop')\n  .K('pop')\n  .T('pop')\n  # => returns 7\n```\n\n## How does that make my code more fluent?\n\nYou're familiar with [fluent interfaces][fluent]. They're great, but they rely on the author of the API making sure that each function returns its receiver. The `.K` method allows you to make any function or method \"fluent\" even if the original author has other ideas. The `.K` and `.T` methods also allow you to write your own methods and 'call' them just as if they were baked into the original object. For example, you can fake an `identifiers` filter for arrays of strings:\n\n[fluent]: http://en.wikipedia.org/wiki/Fluent_interface\n\n```coffeescript\nrequire 'underscore'\n\nidentifiers = (arrOfSymbols) ->\n  _.select arrOfSymbols, (str) ->\n    /^[_a-zA-Z]\\w*$/.test(str)\n  \nsomeArray\n  .T(identifiers)\n  .K('someMethodName')\n  .T(someOtherFilter)\n```\n\nThis is cleaner than trying to mix oridinary functions with methods and adopting tenporary variables when you want to work around what the function was written to return. In this example, having extended `Array.prototype` with `.K` and `.T` once, you need not extend it any more to add your own custom methods.\n\nTo recap:\n\n1. You can make any function into something that can be called like a method, making your code read more naturally, and;\n2. You can give any function or built-in method either \"fluent\" (return the receiver) or \"pipeline\" (return its value) semantics as you please.\n\n## Monkey-patching is evil!\n\nI agree. `KT(foo).K(...)` and `KT(foo).T(...)` work just fine without mixing `.K` and `.T` into an existing class, much as `_(...).tap` and other methods work without modifying an existing class. Also:\n\n```coffeescript\n\nKT([1..10])\n  .chain()\n  .K('pop')\n  .K('pop')\n  .K('pop')\n  .T('pop')\n  .value()\n  # => returns 7\n```\n\n## Stuff and nonsense, this is a syntax issue, not a functional issue\n\n[I agree][sans-titre], but that being said:\n\n1. You can use katy now instead of waiting to see if Coffeescript adopts a syntax for chaining methods, and;\n2. The `.K` and `.T` methods turn any function into something you can call like a method, which makes your code read more cleanly.\n\n[sans-titre]: https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md \"Sans Titre\"\n  \n## Is Katy any good?\n\n[Yes][y].\n\n[y]: http://news.ycombinator.com/item?id=3067434\n\n[um]: https://github.com/raganwald/Underscore-Matchers-for-Jasmine\n\n## Cool! Does it work with jQuery?\n\nYes, but if you like jQuery and like Katy, you'll love [jQuery Combinators][jc].\n\n[jc]: https://github.com/raganwald/JQuery-Combinators\n\n## Calling a method by name is cool, but can you do more with Strings?\n\nTry `KT.installStringLambdas()`. The result is not to everybody's taste, but those who like it, like it a lot.\n\n## What's with the naming conventions?\n\n`.T` is known in some CS circles as the [Thrush][t] or `T` combinator. Likewise, `.K` is known in combinatory logic circles as the \"K Combinator\" or [Kestrel][k]. To simplify the explanation radically, `T` and `K` are called combinators because they combine things to produce a result in different ways. Functional programmers call such things higher-order functions, but what makes combinators interesting is that combinators work by rearranging the order of things in an expression.\n\nFor example, `T` reverses the order of two things. Think about it: Instead of writing `identifiers(some_array)`, we use `T` to write `some_array.T(identifiers)`. That rearrangement is very handy for making our code conform to fluent style. Likewise, `K` leaves them in the same order but removes something. This ability to rearrange things is what makes them so useful for taking code that would normally have function calls sprinkled throughout it and rearranging it into a nice tree of method calls in fluent style.\n\nMany other combinators exist, and they are all interesting with applications for functional and OO programmers. With combinators you can even get rid of parentheses in a programming language! If you aren't familiar with Combinatory Logic, I encourage you to follow the links to my posts about Kestrels and Thrushes, and better still do a little digging about Combinatory Logic in general. It's a rich, fascinating field of study that is so simple it's incredibly easy to pick up, and it leads naturally into functional and [concatenative][joy] languages.\n\n[k]: http://github.com/raganwald/homoiconic/blob/master/2008-10-29/kestrel.markdown#readme\n[t]: http://github.com/raganwald/homoiconic/blob/master/2008-10-30/thrush.markdown#readme\n[joy]: http://github.com/raganwald/homoiconic/blob/master/2008-11-16/joy.md#readme","maintainers":[{"name":"raganwald","email":"raganwald@gmail.com"}],"time":{"modified":"2022-06-13T02:14:39.182Z","created":"2011-12-05T23:53:48.245Z","0.0.4":"2011-12-05T23:53:49.053Z","0.0.5":"2011-12-06T00:17:28.138Z","0.0.6":"2011-12-07T21:43:22.649Z","1.0.0":"2011-12-08T16:17:43.776Z"},"author":{"name":"Reg Braithwaite","email":"raganwald@gmail.com","url":"http://reginald.braythwayt.com"},"repository":{"type":"git","url":"git://github.com/raganwald/Katy.git"}}