Home | Notifications | New Note | Local | Federated | Search | Logout

Note Detail


Reply to @layarlaut@misskey.id
tembok@tembok@misskey.id (2026-09-19 07:38:46)
@layarlaut ohh til

Tbh I'm still confused on what's considered a pure function. Like in the resource that I use to learn about pure function, it says that suppose you have these functions:
func A() {
....
}

func B() {
....
A(....)
....
}

They said that func B is impure, and you should write it like this
func A() {
....
}

func B(A) {
....
A(....)
....
}

Isn't that just gonna make writing a function a hassle? Since you need to type every "dependency" into the parameter
---Reply--- Layar Laut@layarlaut@misskey.id (2026-09-19 09:06:48) @tembok where do you read that? as long as A is pure. It's fine to directly call A inside B.

And in the case A is impure and B needs some thing from A, the result of A is the one that should be passed along rather than A itself. Passing A would make B impure.

The only time you need to pass a function is when you need different functionality depending with the same structure or when you need dependency injection
Reply

---Replies---
Layar Laut@layarlaut@misskey.id (2026-09-19 09:17:20)
@tembok even then dependency injection is reserved to the outer most function that talk to the outside world