pair = cons(1, 2) # => Proc
pair.call(:car) == car(pair) == 1
pair.call(:cdr) == cdr(pair) == 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function.prototype.curry = function(...args) { | |
| let fn = this; | |
| let f = (...restArgs) => { | |
| if (fn.length < args.length + restArgs.length) { | |
| args = args.concat(restArgs); | |
| return fn.apply(this, args.slice(0, fn.length)); | |
| } else { | |
| args = args.concat(restArgs); | |
| return f; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Gray_code | |
| def self.encode number | |
| ( number ^ ( number >> 1 ) ).to_s(2) | |
| end | |
| def self.decode number | |
| bin = number[0] | |
| (number.length-1).times do |i| | |
| bin += ( number[i+1].to_i(2) ^ bin[i].to_i(2) ).to_s(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Simple bijective function | |
| # Basically encodes any integer into a base(n) string, | |
| # where n is ALPHABET.length. | |
| # Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047 | |
| ALPHABET = | |
| "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//) | |
| # make your own alphabet using: | |
| # (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join |
This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.
###Array ####Definition:
- Stores data elements based on an sequential, most commonly 0 based, index.
- Based on tuples from set theory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sumyuga [7:57 PM] вот такой вопрос меня последние два дня волнует: | |
| а пишут ли веб в функциональном стиле? читал что Lisp используют для веба и даже в продакшене он себя хорошо чувствует. | |
| просто на мой взгляд это скорее эзотерика, хотя с приходом reactjs может многое изменится, кто что думает? | |
| kirill.mokevnin [8:05 PM] | |
| В функциональном стиле пишут функции, а не веб | |
| когда в любом языке программирования вы используете функцию map, вы пишите этот кусочек программы в функциональном стиле | |
| sumyuga [8:06 PM] | |
| ну в общем вы меня поняли )) да, есть же clojure, совсем забыл )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kirill.mokevnin [8:19 PM] | |
| тут в соседнем чате спросили почему дефолты в базе зло, но по скольку это касается не только руби, предлагаю обсудить | |
| kirill.mokevnin [8:19 PM] | |
| тут | |
| kirill.mokevnin [8:20 PM] | |
| Кто согласен не согласен? | |
| ivanlemeshev [8:21 PM] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Nothing | |
| def >> fn | |
| self | |
| end | |
| def value | |
| nil | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let compose = (...fns) => x => fns.reverse().reduce((acc, f) => f(acc), x); | |
| let map = f => x => x.map(f); | |
| let log = function() { | |
| console.log(this); | |
| return this; | |
| }; | |
| let toUpperCase = x => x.toUpperCase(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let compose = (...fns) => x => fns.reverse().reduce((acc, f) => f(acc), x); | |
| let map = f => functor => functor.map(f); | |
| let log = function() { | |
| console.log(this); | |
| return this; | |
| }; | |
| let Maybe = function(x) { | |
| this.__value = x; |