Skip to content

Commit 4966a8d

Browse files
committed
init
0 parents  commit 4966a8d

30 files changed

+524
-0
lines changed

.editorconfig

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SCX EditorConfig v1.0
2+
root = true
3+
4+
[*]
5+
# 字符集
6+
charset = utf-8
7+
# 行分割符
8+
end_of_line = lf
9+
# 缩进样式
10+
indent_style = space
11+
# 缩进
12+
indent_size = 4
13+
# 制表符大小
14+
tab_width = 4
15+
# 去除行尾空白字符
16+
trim_trailing_whitespace = true
17+
# 在文件末尾插入换行符
18+
insert_final_newline = true
19+
# 强制换行位置
20+
max_line_length = 120
21+
22+
[*.java]
23+
# 简单的 块 在同一行
24+
ij_java_keep_simple_blocks_in_one_line = false
25+
# 简单的 方法 在同一行
26+
ij_java_keep_simple_methods_in_one_line = false
27+
# 简单的 lambda 在同一行
28+
ij_java_keep_simple_lambdas_in_one_line = true
29+
# 简单的 类 在同一行
30+
ij_java_keep_simple_classes_in_one_line = true
31+
# 'if()' 语句 强制加大括号
32+
ij_java_if_brace_force = always
33+
# 'for()' 语句 强制加大括号
34+
ij_java_for_brace_force = always
35+
# 'while()' 语句 强制加大括号
36+
ij_java_while_brace_force = always
37+
# 'do...while()' 语句 强制加大括号
38+
ij_java_do_while_brace_force = always
39+
40+
[*.js]
41+
# 使用使用 双引号
42+
ij_javascript_use_double_quotes = true
43+
# 强制 引号样式
44+
ij_javascript_force_quote_style = true
45+
# 在语句末尾使用 分号
46+
ij_javascript_use_semicolon_after_statement = true
47+
# 强制 分号样式
48+
ij_javascript_force_semicolon_style = true
49+
# 'if()' 语句 强制加大括号
50+
ij_javascript_if_brace_force = always
51+
# 'for()' 语句 强制加大括号
52+
ij_javascript_for_brace_force = always
53+
# 'while()' 语句 强制加大括号
54+
ij_javascript_while_brace_force = always
55+
# 'do...while()' 语句 强制加大括号
56+
ij_javascript_do_while_brace_force = always
57+
58+
[*.html]
59+
# 引号样式
60+
ij_html_quote_style = double
61+
# 强制引号
62+
ij_html_enforce_quotes = true
63+
64+
[*.css]
65+
# 使用 双引号
66+
ij_css_use_double_quotes = true
67+
# 强制引号格式
68+
ij_css_enforce_quotes_on_format = true
69+
70+
[*.json]
71+
# 缩进
72+
indent_size = 2
73+
74+
[*.md]
75+
# 去除行尾空白字符 (MarkDown 行尾空白有特殊含义)
76+
trim_trailing_whitespace = false
77+
78+
[*.{yaml,yml}]
79+
# 缩进
80+
indent_size = 2

.github/dependabot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: maven
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
groups:
8+
maven-all:
9+
patterns:
10+
- "*"
11+
12+
- package-ecosystem: github-actions
13+
directory: /
14+
schedule:
15+
interval: weekly
16+
groups:
17+
github-actions-all:
18+
patterns:
19+
- "*"

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
- workflow_dispatch
6+
jobs:
7+
ci:
8+
name: CI
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: 检出代码
12+
uses: actions/checkout@v5
13+
14+
- name: 配置 Java
15+
uses: actions/setup-java@v5
16+
with:
17+
java-version: 25
18+
distribution: temurin
19+
cache: maven
20+
21+
- name: Maven 构建
22+
run: mvn package
23+
24+
- name: 上传构建产物
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: scx-function-artifact
28+
path: ./target/

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Maven ###
2+
target/
3+
4+
### IntelliJ IDEA ###
5+
.idea/
6+
*.iws
7+
*.iml
8+
*.ipr

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 scx567888
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<p align="center">
2+
<img src="https://scx.cool/scx-logo/scx-function-logo.svg" width="300px" alt="scx-function-logo"/>
3+
</p>
4+
<p align="center">
5+
<a target="_blank" href="https://github.com/scx-projects/scx-function/actions/workflows/ci.yml">
6+
<img src="https://github.com/scx-projects/scx-function/actions/workflows/ci.yml/badge.svg" alt="CI"/>
7+
</a>
8+
<a target="_blank" href="https://central.sonatype.com/artifact/cool.scx/scx-function">
9+
<img src="https://img.shields.io/maven-central/v/cool.scx/scx-function?color=ff69b4" alt="maven-central"/>
10+
</a>
11+
<a target="_blank" href="https://github.com/scx-projects/scx-function">
12+
<img src="https://img.shields.io/github/languages/code-size/scx-projects/scx-function?color=orange" alt="code-size"/>
13+
</a>
14+
<a target="_blank" href="https://github.com/scx-projects/scx-function/issues">
15+
<img src="https://img.shields.io/github/issues/scx-projects/scx-function" alt="issues"/>
16+
</a>
17+
<a target="_blank" href="https://github.com/scx-projects/scx-function/blob/master/LICENSE">
18+
<img src="https://img.shields.io/github/license/scx-projects/scx-function" alt="license"/>
19+
</a>
20+
</p>

pom.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>cool.scx</groupId>
8+
<artifactId>scx-parent</artifactId>
9+
<version>28</version>
10+
<relativePath/>
11+
</parent>
12+
13+
<artifactId>scx-function</artifactId>
14+
<version>1.0.0</version>
15+
<packaging>jar</packaging>
16+
17+
<name>SCX Function</name>
18+
<description>
19+
SCX Function
20+
</description>
21+
<url>https://github.com/scx-projects/scx-function</url>
22+
23+
<licenses>
24+
<license>
25+
<name>MIT License</name>
26+
<url>https://github.com/scx-projects/scx-function/blob/master/LICENSE</url>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<id>scx567888</id>
33+
<name>scx567888</name>
34+
<email>scx567888@outlook.com</email>
35+
</developer>
36+
</developers>
37+
38+
<scm>
39+
<connection>scm:git:https://github.com/scx-projects/scx-function.git</connection>
40+
<developerConnection>scm:git:https://github.com/scx-projects/scx-function.git</developerConnection>
41+
<url>https://github.com/scx-projects/scx-function</url>
42+
</scm>
43+
44+
<build>
45+
<plugins>
46+
47+
<!-- 此插件用于将项目打包为 可执行 jar 包-->
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-jar-plugin</artifactId>
51+
<configuration>
52+
<archive>
53+
<manifest>
54+
<!-- 因为 scx 并不是可执行 jar 包, 所以此处不添加 classpath 到描述文件中 -->
55+
<addClasspath>false</addClasspath>
56+
</manifest>
57+
</archive>
58+
<!-- 此处因为没有类似 maven-source-plugin 插件中 excludeResources 的选项 -->
59+
<!-- 所以在这里手动排除资源文件 , 具体文件说明见下方 -->
60+
<excludes>
61+
<!-- 默认 git 占位空文件 -->
62+
<exclude>/.gitkeep</exclude>
63+
</excludes>
64+
</configuration>
65+
</plugin>
66+
67+
</plugins>
68+
</build>
69+
70+
<dependencies>
71+
72+
<!-- TestNG 测试包 -->
73+
<dependency>
74+
<groupId>org.testng</groupId>
75+
<artifactId>testng</artifactId>
76+
<version>${testng.version}</version>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
</dependencies>
81+
82+
<properties>
83+
84+
<!-- *********************** 以下为依赖包版本 *********************** -->
85+
<testng.version>7.11.0</testng.version>
86+
87+
</properties>
88+
89+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cool.scx.function;
2+
3+
@FunctionalInterface
4+
public interface Function0<R, X extends Throwable> {
5+
6+
R apply() throws X;
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cool.scx.function;
2+
3+
@FunctionalInterface
4+
public interface Function0Void<X extends Throwable> {
5+
6+
void apply() throws X;
7+
8+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cool.scx.function;
2+
3+
/// 设计哲学与背景说明:
4+
///
5+
/// 1. 函数式接口的存在是 Java 语言的一个 "不得已而为之" 的产物.
6+
/// Java 本身对函数作为一等公民的支持远不如一些函数式语言,
7+
/// 因此需要通过函数式接口来模拟函数行为.
8+
/// 本接口力求在这种限制下尽可能的还原 "函数" 的本质.
9+
///
10+
/// 2. 命名哲学:
11+
/// 函数式接口的命名, 要么做到 "具体业务语义明确",
12+
/// 要么做到 "绝对中立且结构统一".
13+
/// JDK 自带的 Supplier, Consumer, Function 等接口,
14+
/// 既不够具体, 又不够中立, 命名语义模糊, 使用时需要人为推断含义, 增加了认知负担.
15+
/// 本接口选择保持绝对中立, 仅表达 "参数个数" 和 "返回值有无".
16+
///
17+
/// 3. 关于异常传播:
18+
/// JDK 的函数式接口不支持抛出受检异常 (Checked Exception),
19+
/// 这导致实际开发中, 处理受检异常会非常繁琐, 需要手动捕获或者强行转换为 RuntimeException.
20+
/// 本接口通过泛型参数 X extends Throwable 支持异常泛型,
21+
/// 让函数式接口能自然传播受检异常 避免异常封装与侵入式捕获.
22+
/// 这其实还原了 "函数" 的最本质的概念.
23+
///
24+
/// 4. 关于基本类型特化:
25+
/// 虽然基本类型特化 (如 IntFunction) 可以避免装箱拆箱的性能损耗,
26+
/// 但全面特化所有参数和返回值, 会导致类的数量呈指数级爆炸, 达到不可维护的规模 (理论上亿级别).
27+
/// 经过权衡, 我们放弃全面特化.
28+
/// 当然随着 Java 未来的发展, 可能会引入基本类型的泛型支持 (如 Project Valhalla).
29+
/// 届时本接口也能够自然支持, 无需做任何改动.
30+
///
31+
/// 5. 命名规则说明:
32+
/// - 接口名称采用统一格式: Function + 参数个数 + (Void 表示无返回值)
33+
/// 例如 Function2 表示两个参数有返回值的函数, Function3Void 表示三个参数无返回值的函数.
34+
/// - 泛型参数统一按字母顺序排列 (A, B, C, D...), 异常类型统一为 X extends Throwable.
35+
/// - 方法名固定为 apply, 保持接口简洁一致.
36+
///
37+
/// 6. 相比 Java 自带接口的优势:
38+
/// - 命名与结构完全中立, 仅表示 "函数" 这一概念, 避免了含糊不清的命名.
39+
/// - 支持受检异常传播, 提升异常处理能力.
40+
/// - 命名结构统一, 便于快速识别和使用.
41+
/// - 放弃不必要的类型特化, 保持代码库轻量.
42+
@FunctionalInterface
43+
public interface Function1<A, R, X extends Throwable> {
44+
45+
R apply(A a) throws X;
46+
47+
}

0 commit comments

Comments
 (0)