fixed fences in the docs
This commit is contained in:
parent
5f1e6564d5
commit
75e2b63923
10
docs/OOP.md
10
docs/OOP.md
@ -566,7 +566,7 @@ c.increment() // OK
|
|||||||
|
|
||||||
You can also apply restricted visibility to custom property setters:
|
You can also apply restricted visibility to custom property setters:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
class Person(private var _age: Int) {
|
class Person(private var _age: Int) {
|
||||||
var age
|
var age
|
||||||
get() = _age
|
get() = _age
|
||||||
@ -578,7 +578,7 @@ class Person(private var _age: Int) {
|
|||||||
|
|
||||||
A `protected set` allows subclasses to modify a field that is otherwise read-only to the public:
|
A `protected set` allows subclasses to modify a field that is otherwise read-only to the public:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
class Base {
|
class Base {
|
||||||
var state = "initial"
|
var state = "initial"
|
||||||
protected set
|
protected set
|
||||||
@ -761,7 +761,7 @@ Just like methods, you can extend existing classes with properties. These can be
|
|||||||
|
|
||||||
A read-only extension can be defined by assigning an expression:
|
A read-only extension can be defined by assigning an expression:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
val String.isLong = length > 10
|
val String.isLong = length > 10
|
||||||
|
|
||||||
val s = "Hello, world!"
|
val s = "Hello, world!"
|
||||||
@ -772,7 +772,7 @@ assert(s.isLong)
|
|||||||
|
|
||||||
For more complex logic, use `get()` and `set()` blocks:
|
For more complex logic, use `get()` and `set()` blocks:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
class Box(var value: Int)
|
class Box(var value: Int)
|
||||||
|
|
||||||
var Box.doubledValue
|
var Box.doubledValue
|
||||||
@ -795,7 +795,7 @@ Extensions in Lyng are **scope-isolated**. This means an extension is only visib
|
|||||||
|
|
||||||
You can define different extensions with the same name in different scopes:
|
You can define different extensions with the same name in different scopes:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
fun scopeA() {
|
fun scopeA() {
|
||||||
val Int.description = "Number: " + toString()
|
val Int.description = "Number: " + toString()
|
||||||
assertEquals("Number: 42", 42.description)
|
assertEquals("Number: 42", 42.description)
|
||||||
|
|||||||
@ -136,7 +136,7 @@ Serializable class that conveys information about the exception. Important membe
|
|||||||
|
|
||||||
A simple structire that stores single entry in Lyng stack, it is created automatically on exception creation:
|
A simple structire that stores single entry in Lyng stack, it is created automatically on exception creation:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
class StackTraceEntry(
|
class StackTraceEntry(
|
||||||
val sourceName: String,
|
val sourceName: String,
|
||||||
val line: Int,
|
val line: Int,
|
||||||
|
|||||||
@ -72,7 +72,7 @@ Tip: If a closure unexpectedly cannot see an outer local, check whether an inter
|
|||||||
|
|
||||||
The `cached` function (defined in `lyng.stdlib`) is a classic example of using closures to maintain state. It wraps a builder into a zero-argument function that computes once and remembers the result:
|
The `cached` function (defined in `lyng.stdlib`) is a classic example of using closures to maintain state. It wraps a builder into a zero-argument function that computes once and remembers the result:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
fun cached(builder) {
|
fun cached(builder) {
|
||||||
var calculated = false
|
var calculated = false
|
||||||
var value = null
|
var value = null
|
||||||
|
|||||||
@ -1553,13 +1553,13 @@ It is extremely simple to use: you pass it a block (lambda) that performs the co
|
|||||||
|
|
||||||
### Basic Example
|
### Basic Example
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
val expensive = cached {
|
val expensive = cached {
|
||||||
println("Performing expensive calculation...")
|
println("Performing expensive calculation...")
|
||||||
2 + 2
|
2 + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
println(expensive()) // Prints "Performing expensive calculation..." then "4"
|
println(expensive()) // Prints "Performing expensive calculation...") then "4"
|
||||||
println(expensive()) // Prints only "4" (result is cached)
|
println(expensive()) // Prints only "4" (result is cached)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -1573,7 +1573,7 @@ println(expensive()) // Prints only "4" (result is cached)
|
|||||||
|
|
||||||
This is the most common use case for `cached`. It allows you to define expensive "fields" that are only computed if someone actually uses them:
|
This is the most common use case for `cached`. It allows you to define expensive "fields" that are only computed if someone actually uses them:
|
||||||
|
|
||||||
```kotlin
|
```lyng
|
||||||
class User(val id: Int) {
|
class User(val id: Int) {
|
||||||
// The details will be fetched only once, on demand
|
// The details will be fetched only once, on demand
|
||||||
val details = cached {
|
val details = cached {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user