Skip to content

Commit 0d8b76b

Browse files
committed
update README
1 parent 4895914 commit 0d8b76b

1 file changed

Lines changed: 40 additions & 36 deletions

File tree

README.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ A set of scope functions for Java.
2525

2626
JLet is a set of scope functions for Java, similar to Kotlin's scope functions but Java-specific.
2727

28-
When you call a scope function on an object with a lambda expression provided, it forms a temporary scope. In this
29-
scope, you can access the object as a lambda expression argument.
28+
When you call a scope function with an object and a lambda expression, it forms a temporary scope. In this scope, you
29+
can access the object as a lambda expression argument.
3030

3131
## How to use
3232

@@ -70,87 +70,91 @@ dependencies {
7070

7171
### `let`
7272

73-
* has arguments (from 1 to 8)
74-
* has result
73+
* has value arguments (from 1 to 8)
74+
* has result (lambda expression result)
7575

7676
<!-- @formatter:off -->
7777
```java
78-
String origin = "abcdef";
79-
String result = let(origin.toLowerCase(), origin.toUpperCase(), (lower, upper) ->
80-
lower + upper
78+
String shortString = let(someObject.toString(), s ->
79+
s.length() > 10 ? s.substring(0, 11) : s
8180
);
8281
```
8382
<!-- @formatter:on -->
8483

8584
### `test`
8685

87-
* has arguments (from 0 to 8)
88-
* has result (`boolean`)
86+
* has value arguments (from 0 to 8)
87+
* has result (lambda expression `boolean` result)
8988

9089
<!-- @formatter:off -->
9190
```java
92-
if (test(() -> {
93-
// calculations
94-
return true;
95-
})) {
91+
if (test(someObject.toString(), s -> s.length() > 10 && s.contains("."))) {
9692
System.out.println("OK");
9793
}
9894
```
9995
<!-- @formatter:on -->
10096

10197
### `run`
10298

103-
* has no arguments
99+
* has no value arguments
104100
* has no result
105101

106102
<!-- @formatter:off -->
107103
```java
108-
run(() ->
109-
System.out.println("OK")
110-
);
104+
run(() -> {
105+
String localVariable1 = "string1";
106+
String localVariable2 = "string2";
107+
System.out.println(localVariable1);
108+
System.out.println(localVariable2);
109+
});
111110
```
112111
<!-- @formatter:on -->
113112

114113
### `with`
115114

116-
* has arguments (from 1 to 8)
115+
* has value arguments (from 1 to 8)
117116
* has no result
118117

119118
<!-- @formatter:off -->
120119
```java
121-
String origin = "abcdef";
122-
with(origin.substring(0, 3), substring ->
123-
System.out.println("substring: " + substring)
124-
);
120+
with(someObject.toString(), s -> {
121+
String shortString = s.length() > 10 ? s.substring(0, 11) : s;
122+
System.out.println(shortString);
123+
});
125124
```
126125
<!-- @formatter:on -->
127126

128127
### `it`
129128

130-
* has arguments (from 0 to 8)
131-
* has result (function result for the case of no arguments or the first value for others)
129+
There are two options
130+
131+
* has no value arguments
132+
* has result (lambda expression result)
132133

133134
<!-- @formatter:off -->
134135
```java
135-
Map<Integer, String> map = it(new HashMap<>(), m -> {
136+
someObject.setString(it(() -> {
137+
// calculations
138+
return "string";
139+
}));
140+
```
141+
<!-- @formatter:on -->
142+
143+
* has value arguments (from 1 to 8)
144+
* has result (the first value argument)
145+
146+
<!-- @formatter:off -->
147+
```java
148+
someObject.setMap(it(new HashMap<>(), m -> {
136149
m.put(1, "first");
137150
m.put(2, "second");
138-
});
139-
140-
MyObj myObj = new MyObjBuilder()
141-
.setValue1(100)
142-
.setValue2(it(() -> {
143-
// calculations
144-
return 200;
145-
}))
146-
.setValue3(it(map, m -> System.out.println(m)))
147-
.build();
151+
}));
148152
```
149153
<!-- @formatter:on -->
150154

151155
## Checked exceptions
152156

153-
All of these functions ignore checked exceptions.
157+
All of these functions allow not catching checked exceptions.
154158

155159
<!-- @formatter:off -->
156160
```java

0 commit comments

Comments
 (0)