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
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>net.manish</groupId> | |
| <artifactId>scala-simple</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <name>${project.artifactId}</name> | |
| <description>My wonderfull scala app</description> | |
| <inceptionYear>2010</inceptionYear> | |
| <licenses> | |
| <license> |
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
| /** | |
| * |@| is a helper function that helps you accumulate applicative functors. It gives you an ApplicativeBuilder (it's part of | |
| * the implementation though) through which you accumulate your applicatives just as you would using the Builder pattern of | |
| * the GoF in the OO world. Once you have all the applicatives you can pass it a function that will be applied to all the | |
| * values that you have accumulated so far. e.g. | |
| */ | |
| scala> (1.some |@| 2.some) apply {_ + _} | |
| res1: Option[Int] = Some(3) |
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
| -- A simple definition without using any fancy functions. | |
| haskell>let ifMaybe pred value = if pred value then Just value else Nothing | |
| haskell>:t ifMaybe | |
| ifMaybe :: (a -> Bool) -> a -> Maybe a | |
| haskell>ifMaybe (const True) 2 | |
| Just 2 | |
| haskell>ifMaybe (const False) 2 | |
| Nothing | |
| -- Using functions from standard library. |
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
| var NodeList = function() {}; | |
| var nodeListExtras = {x: 23}; | |
| mixin(NodeList.prototype, Array.prototype, nodeListExtras); | |
| function mixin(obj /*, mixins*/) { | |
| var mixins = [].slice.call(arguments, 1); | |
| for (var i=0; i<mixins.length; i++) { | |
| var thisMixin = mixins[i]; | |
| var props = Object.getOwnPropertyNames(thisMixin); | |
| for (var j=0; j<props.length; j++) { |
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
| // Compositional evaluator as visitor | |
| import java.math.BigInteger; | |
| // Syntax | |
| interface Exp { | |
| <X> X accept(Visitor<X> v); | |
| } |
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 Person | |
| def initialize(name, age) | |
| @name = name | |
| @age = age | |
| end | |
| def set_name(new_name) | |
| @name = new_name | |
| 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
| ;; Type annotation for seq, inspired by haskell | |
| ;; (+T <var> :- <interface/protocol>* => <classes>) | |
| (+T clojure.core/seq :- (ISeq a) (ISeq b) => a -> b) | |
| (+T clojure.core/seq :- (Seqable a) (ISeq b) => a -> b) | |
| (+T clojure.core/seq :- nil -> nil) | |
| (+T clojure.core/seq :- (Iterable a) (ISeq b) => a -> b) | |
| (+T clojure.core/seq :- (PrimArray a) (ISeq b) => a -> b) | |
| (+T clojure.core/seq :- (CharSequence a) (ISeq b) => a -> b) |
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
| #!/usr/bin/env python | |
| import flask | |
| import flaskext.script | |
| default_config = { | |
| } | |
| def create_app(): | |
| import views |
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
| Object addTrait := method(obj, | |
| resolutions := call evalArgAt(1) | |
| if(resolutions isNil, resolutions = Map clone) | |
| getSlot("obj") foreachSlot(name, value, | |
| if(getSlot("self") hasLocalSlot(name), | |
| if(name == "type", continue) | |
| if(resolutions at(name) isNil, Exception raise("""Slot '#{name}' already exists in #{getSlot("self") type}[#{getSlot("self") uniqueId}]. Give it a new name in the map argument.""" interpolate)) | |
| getSlot("self") setSlot(resolutions at(name), getSlot("value")) | |
| continue |
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
| /* | |
| * Copyright 2012 Thomas Broyer <t.broyer@ltgt.net> | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |