All it takes to be a Monad is to provide two functions which conform to three laws.
The two functions:
- Place a value into monadic context
- Haskell's Maybe: return / Just
- Scala's Option: Some
package selenium; | |
import java.sql.Driver; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.Wait; |
<!DOCTYPE html> | |
<!-- http://www.sivalabs.in/2014/09/angularjs-different-ways-of-using-array.html --> | |
<html ng-app="myApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>My AngularJS App</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> |
<?xml version="1.0" encoding="UTF-8"?> | |
<databaseChangeLog | |
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | |
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"> | |
<!-- | |
<include file=".+(.sql|.xml)" /> |
//This is an example of how to scrape the web using PhantomJS and jQuery: | |
//source: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery | |
//http://phantomjs.org/ | |
var page = new WebPage(), | |
url = 'http://localhost/a-search-form', | |
stepIndex = 0; | |
/** | |
* From PhantomJS documentation: |
http://passion.forco.de/content/emulating-self-types-using-java-generics-simplif...
The Java programming language does not support the notion of "self types", that is "type of this". When implementing fluent APIs, this lack of support can lead to significant duplication of boilerplate code. Taking FEST Assertions as an example, this article shows how "self types" can be emulated in Java using Generics.
Why bother?
Slides: http://www.ba-horb.de/~pl/talks/Oberseminar_TI_Java8.pdf
Technically speaking, Java does have type inferencing when using generics. With a generic method like
public T foo(T t) {
First off, use-site variance is strictly more powerful than declaration-site variance (although at the cost of concision), or at least Java's wildcards are (which are actually more powerful than use-site variance). This increased power is particularly useful for languages in which stateful constructs are used heavily, such as C# and Java (but Scala much less so, especially since it's standard lists are immutable).
import java.util.*; | |
/* | |
* Covariance and contravariance. | |
* | |
* A type operator (an operator which takes as input a type and returns another type as output) is | |
* said to be | |
* 1) `covariant` if it preserves the ordering of types and orders types | |
* from more specific ones to more generic ones. | |
* 2) `contravariant` if it preserves the ordering of types and orders types |
/** | |
* ``` | |
* Does JDK8's Optional class satisfy the Monad laws? | |
* ================================================= | |
* 1. Left identity: true | |
* 2. Right identity: true | |
* 3. Associativity: true | |
* | |
* Yes, it does. | |
* ``` |