Skip to content

Commit 0a1741b

Browse files
committed
Resolving conflicts in Ord
2 parents eb92358 + 7152326 commit 0a1741b

7 files changed

Lines changed: 312 additions & 11 deletions

File tree

README.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ The Functional Java artifact is published to Maven Central using the group `org.
2828
* the core library (`functionaljava`)
2929
* Java 8 specific support (`functionaljava-java8`)
3030

31-
The latest version is `4.2-beta-1`. This can be added to your Gradle project by adding the dependencies:
31+
The latest version is `4.2`. This can be added to your Gradle project by adding the dependencies:
3232
----
33-
compile "org.functionaljava:functionaljava:4.2-beta-1"
34-
compile "org.functionaljava:functionaljava-java8:4.2-beta-1"
33+
compile "org.functionaljava:functionaljava:4.2"
34+
compile "org.functionaljava:functionaljava-java8:4.2"
3535
----
3636

3737
and in Maven:
3838
----
3939
<dependency>
4040
<groupId>org.functionaljava</groupId>
4141
<artifactId>functionaljava</artifactId>
42-
<version>4.2-beta-1</version>
42+
<version>4.2</version>
4343
</dependency>
4444
<dependency>
4545
<groupId>org.functionaljava</groupId>
4646
<artifactId>functionaljava-java8</artifactId>
47-
<version>4.2-beta-1</version>
47+
<version>4.2</version>
4848
</dependency>
4949
----
5050

core/src/main/java/fj/Ord.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,8 @@ public static <A, B, C> Ord<P3<A, B, C>> p3Ord(final Ord<A> oa, final Ord<B> ob,
474474
* @return An order instance for the <code>Comparable</code> interface.
475475
*/
476476
public static <A extends Comparable<A>> Ord<A> comparableOrd() {
477-
return ord(a1 -> a2 -> {
478-
final int x = a1.compareTo(a2);
479-
return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT;
480-
});
477+
478+
return ord(a1 -> a2 -> Ordering.fromInt(a1.compareTo(a2)));
481479
}
482480

483481
/**

core/src/main/java/fj/Ordering.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ public enum Ordering {
2020
/**
2121
* Greater than.
2222
*/
23-
GT
23+
GT;
24+
25+
public int toInt() { return ordinal() - 1 ; }
26+
public static Ordering fromInt(int cmp) {
27+
return cmp == 0 ? EQ : cmp > 0 ? GT : LT;
28+
}
2429
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package fj.data;
2+
3+
import fj.F;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
import static fj.data.List.list;
8+
import static fj.data.Option.none;
9+
import static fj.data.Option.some;
10+
11+
/**
12+
* Created by amar on 28/12/14.
13+
*/
14+
public class OptionTests {
15+
16+
@Test
17+
public void ShouldTraverseListWithGivenFunction(){
18+
List<String> strings = list("some1", "some2", "some3", "not_some", " ");
19+
F<String, Option<String>> f = s -> {
20+
if(s.startsWith("some"))
21+
return some(s);
22+
else
23+
return Option.none();
24+
};
25+
26+
Option<List<String>> optStr = Option.traverse(strings, f);
27+
Assert.assertEquals("optStr should be none", Option.none(), optStr);
28+
}
29+
30+
@Test
31+
public void ShouldTraverseListWithGivenFunction2(){
32+
List<String> strings = list("some1", "some2", "some3");
33+
F<String, Option<String>> f = s -> {
34+
if(s.startsWith("some"))
35+
return some(s);
36+
else
37+
return Option.none();
38+
};
39+
40+
Option<List<String>> optStr = Option.traverse(strings, f);
41+
Assert.assertEquals("optStr should be some", optStr.isSome(), true);
42+
Assert.assertArrayEquals(optStr.some().toArray().array(), new String[]{"some1", "some2", "some3"});
43+
}
44+
45+
@Test
46+
public void ShouldSequenceListOfOptionalContexts(){
47+
List<Option<String>> strings = list(some("some1"), some("some2"), some("some3"));
48+
49+
50+
Option<List<String>> optStr = Option.sequence(strings);
51+
Assert.assertEquals("should be some", optStr.isSome(), true);
52+
Assert.assertArrayEquals(optStr.some().toArray().array(), new String[]{"some1", "some2", "some3"});
53+
}
54+
55+
@Test
56+
public void ShouldSequenceListOfOptionalContexts2(){
57+
List<Option<String>> strings = list(some("some1"), some("some2"), none());
58+
59+
60+
Option<List<String>> optStr = Option.sequence(strings);
61+
Assert.assertEquals("should be some", optStr.isNone(), true);
62+
}
63+
}

etc/release-notes.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
Release Notes
33
=============
44

5+
4.3
6+
===
7+
Target date: To be decided
8+
9+
* Enhancements
10+
* To be decided
11+
* Fixes
12+
* To be decided
13+
514
4.2
615
===
7-
Release target: Aug 2014
16+
Released: 20 December, 2014
817

918
* Enhancements
1019
* Added Java 8 examples

functionaljava.ipr

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="4">
3+
<component name="CompilerConfiguration">
4+
<option name="DEFAULT_COMPILER" value="Javac" />
5+
<resourceExtensions>
6+
<entry name=".+\.(properties|xml|html|dtd|tld)" />
7+
<entry name=".+\.(gif|png|jpeg|jpg)" />
8+
</resourceExtensions>
9+
<wildcardResourcePatterns>
10+
<entry name="!?*.java" />
11+
<entry name="!?*.groovy" />
12+
</wildcardResourcePatterns>
13+
<annotationProcessing>
14+
<profile default="true" name="Default" enabled="false">
15+
<processorPath useClasspath="true" />
16+
</profile>
17+
</annotationProcessing>
18+
<bytecodeTargetLevel target="1.8" />
19+
</component>
20+
<component name="CopyrightManager" default="">
21+
<module2copyright />
22+
</component>
23+
<component name="DependencyValidationManager">
24+
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
25+
</component>
26+
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
27+
<component name="EntryPointsManager">
28+
<entry_points version="2.0" />
29+
</component>
30+
<component name="GradleUISettings">
31+
<setting name="root" />
32+
</component>
33+
<component name="GradleUISettings2">
34+
<setting name="root" />
35+
</component>
36+
<component name="IdProvider" IDEtalkID="11DA1DB66DD62DDA1ED602B7079FE97C" />
37+
<component name="JavadocGenerationManager">
38+
<option name="OUTPUT_DIRECTORY" />
39+
<option name="OPTION_SCOPE" value="protected" />
40+
<option name="OPTION_HIERARCHY" value="true" />
41+
<option name="OPTION_NAVIGATOR" value="true" />
42+
<option name="OPTION_INDEX" value="true" />
43+
<option name="OPTION_SEPARATE_INDEX" value="true" />
44+
<option name="OPTION_DOCUMENT_TAG_USE" value="false" />
45+
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
46+
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
47+
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
48+
<option name="OPTION_DEPRECATED_LIST" value="true" />
49+
<option name="OTHER_OPTIONS" value="" />
50+
<option name="HEAP_SIZE" />
51+
<option name="LOCALE" />
52+
<option name="OPEN_IN_BROWSER" value="true" />
53+
</component>
54+
<component name="Palette2">
55+
<group name="Swing">
56+
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
57+
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
58+
</item>
59+
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
60+
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
61+
</item>
62+
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
63+
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
64+
</item>
65+
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
66+
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
67+
</item>
68+
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
69+
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
70+
<initial-values>
71+
<property name="text" value="Button" />
72+
</initial-values>
73+
</item>
74+
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
75+
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
76+
<initial-values>
77+
<property name="text" value="RadioButton" />
78+
</initial-values>
79+
</item>
80+
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
81+
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
82+
<initial-values>
83+
<property name="text" value="CheckBox" />
84+
</initial-values>
85+
</item>
86+
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
87+
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
88+
<initial-values>
89+
<property name="text" value="Label" />
90+
</initial-values>
91+
</item>
92+
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
93+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
94+
<preferred-size width="150" height="-1" />
95+
</default-constraints>
96+
</item>
97+
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
98+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
99+
<preferred-size width="150" height="-1" />
100+
</default-constraints>
101+
</item>
102+
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
103+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
104+
<preferred-size width="150" height="-1" />
105+
</default-constraints>
106+
</item>
107+
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
108+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
109+
<preferred-size width="150" height="50" />
110+
</default-constraints>
111+
</item>
112+
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
113+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
114+
<preferred-size width="150" height="50" />
115+
</default-constraints>
116+
</item>
117+
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
118+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
119+
<preferred-size width="150" height="50" />
120+
</default-constraints>
121+
</item>
122+
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
123+
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
124+
</item>
125+
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
126+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
127+
<preferred-size width="150" height="50" />
128+
</default-constraints>
129+
</item>
130+
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
131+
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
132+
<preferred-size width="150" height="50" />
133+
</default-constraints>
134+
</item>
135+
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
136+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
137+
<preferred-size width="150" height="50" />
138+
</default-constraints>
139+
</item>
140+
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
141+
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
142+
<preferred-size width="200" height="200" />
143+
</default-constraints>
144+
</item>
145+
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
146+
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
147+
<preferred-size width="200" height="200" />
148+
</default-constraints>
149+
</item>
150+
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
151+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
152+
</item>
153+
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
154+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
155+
</item>
156+
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
157+
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
158+
</item>
159+
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
160+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
161+
</item>
162+
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
163+
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
164+
<preferred-size width="-1" height="20" />
165+
</default-constraints>
166+
</item>
167+
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
168+
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
169+
</item>
170+
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
171+
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
172+
</item>
173+
</group>
174+
</component>
175+
<component name="ProjectModuleManager">
176+
<modules>
177+
<module fileurl="file://$PROJECT_DIR$/functionaljava.iml" filepath="$PROJECT_DIR$/functionaljava.iml" />
178+
</modules>
179+
</component>
180+
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
181+
<output url="file://$PROJECT_DIR$/out" />
182+
</component>
183+
<component name="SvnBranchConfigurationManager">
184+
<option name="mySupportsUserInfoFilter" value="true" />
185+
</component>
186+
<component name="VcsDirectoryMappings">
187+
<mapping directory="" vcs="" />
188+
</component>
189+
</project>
190+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fj.data;
2+
3+
import java.util.stream.Collector;
4+
5+
public final class Collectors {
6+
7+
private Collectors() {
8+
}
9+
10+
public static <A> Collector<A, List.Buffer<A>, List<A>> toList() {
11+
return Collector.of(
12+
List.Buffer::new,
13+
List.Buffer::snoc,
14+
(acc1, acc2) -> acc1.append(acc2.toList()),
15+
List.Buffer::toList
16+
);
17+
}
18+
19+
public static <A> Collector<A, List.Buffer<A>, Array<A>> toArray() {
20+
return Collector.of(
21+
List.Buffer::new,
22+
List.Buffer::snoc,
23+
(acc1, acc2) -> acc1.append(acc2.toList()),
24+
(buf) -> Array.iterableArray(buf.toList())
25+
);
26+
}
27+
28+
public static <A> Collector<A, List.Buffer<A>, Stream<A>> toStream() {
29+
return Collector.of(
30+
List.Buffer::new,
31+
List.Buffer::snoc,
32+
(acc1, acc2) -> acc1.append(acc2.toList()),
33+
(buf) -> Stream.iterableStream(buf.toList())
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)