-
Notifications
You must be signed in to change notification settings - Fork 0
Java02. ДЗ 03, Shevchenko Ilya #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Qwsafex
wants to merge
6
commits into
master
Choose a base branch
from
FunctionalJava
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
729da70
Initial commit
Qwsafex 7b666c1
check
Qwsafex 9e158eb
Added test, serialization and fixed bugs.
Qwsafex 196374a
Everything's done
Qwsafex 5a2f2c1
Removed trash
Qwsafex b5b3e6c
Fixed stuff mentioned in PR comments
Qwsafex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .idea | ||
| .gradle | ||
| build/ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| group 'ru.spbau.shevchenko' | ||
| version '1.0-SNAPSHOT' | ||
|
|
||
| apply plugin: 'java' | ||
|
|
||
| sourceCompatibility = 1.8 | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| testCompile group: 'junit', name: 'junit', version: '4.11' | ||
| } |
Binary file not shown.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #Mon Oct 24 23:58:01 MSK 2016 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| rootProject.name = 'FunctionalJava' | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by ilya on 10/25/16. | ||
| */ | ||
| public class Collections { | ||
| public static <Return, Param> List<Return> map(Function1<? super Param, ? extends Return> f, Iterable<Param> iterable){ | ||
| List<Return> result = new ArrayList<>(); | ||
| iterable.forEach(param -> result.add(f.apply(param))); | ||
| return result; | ||
| } | ||
| public static <Param> List<Param> filter(Predicate<? super Param> f, Iterable<Param> iterable){ | ||
| List<Param> result = new ArrayList<>(); | ||
| for(Param param : iterable){ | ||
| if (f.apply(param)){ | ||
| result.add(param); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| public static <Param> List<Param> takeWhile(Predicate<? super Param> f, Iterable<Param> iterable){ | ||
| List<Param> result = new ArrayList<>(); | ||
| for(Param param : iterable){ | ||
| if (f.apply(param)){ | ||
| result.add(param); | ||
| } | ||
| else{ | ||
| break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| public static <Param> List<Param> takeUnless(Predicate<? super Param> f, Iterable<Param> iterable){ | ||
| return takeWhile(f.not(), iterable); | ||
| } | ||
| public static <Return> Return foldl(Function2<? super Return, ? super Return, ? extends Return> f, Return ini, Iterable<Return> iterable){ | ||
| Return result = ini; | ||
| for(Return a : iterable){ | ||
| result = f.apply(result, a); | ||
| } | ||
| return result; | ||
| } | ||
| public static <Return> Return foldr(Function2<? super Return, ? super Return, ? extends Return> f, Return ini, Iterable<Return> iterable){ | ||
| return foldr(f, ini, iterable.iterator()); | ||
| } | ||
| private static <Return> Return foldr(Function2<? super Return, ? super Return, ? extends Return> f, Return ini, Iterator<Return> iterator) { | ||
| if(!iterator.hasNext()){ | ||
| return ini; | ||
| } | ||
| Return first = iterator.next(); | ||
| return f.apply(first, foldr(f, ini, iterator)); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Created by ilya on 10/24/16. | ||
| */ | ||
| public interface Function1<Param, Return> { | ||
| Return apply(Param xw); | ||
|
|
||
| default <R> Function1<Param, R> compose(Function1<? super Return, ? extends R> g) { | ||
| return param -> g.apply(apply(param)); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Created by ilya on 10/25/16. | ||
| */ | ||
| public interface Function2<Param1, Param2, Return> { | ||
| Return apply(Param1 x, Param2 y); | ||
|
|
||
| default <R> Function2<Param1, Param2, R> compose(Function1<? super Return, ? extends R> g){ | ||
| return (param1, param2) -> g.apply(apply(param1, param2)); | ||
| } | ||
| default Function1<Param2, Return> bind1(Param1 param1){ | ||
| return param2 -> apply(param1, param2); | ||
| } | ||
| default Function1<Param1, Return> bind2(Param2 param2){ | ||
| return param1 -> apply(param1, param2); | ||
| } | ||
| default Function1<Param1, Function1<Param2, Return>> curry(){ | ||
| return this::bind1; | ||
| } | ||
| } | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Created by ilya on 10/25/16. | ||
| */ | ||
| public interface Predicate<Param> extends Function1<Param, Boolean>{ | ||
| Predicate<Object> ALWAYS_TRUE = x -> true; | ||
| Predicate<Object> ALWAYS_FALSE = x -> false; | ||
|
|
||
| default Predicate<Param> not(){ | ||
| return param -> !apply(param); | ||
| } | ||
| default Predicate<Param> or(Predicate<? super Param> g){ | ||
| return param -> apply(param) || g.apply(param); | ||
| } | ||
| default Predicate<Param> and(Predicate<? super Param> g){ | ||
| return param -> apply(param) && g.apply(param); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wildcard'ы?