Skip to content

Instantly share code, notes, and snippets.

View y2k's full-sized avatar
🏠
Working from home

y2k

🏠
Working from home
View GitHub Profile
@y2k
y2k / effector.kt
Created June 3, 2023 21:06
Kotlin Effector
package com.example.frpeffsample.effector
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@y2k
y2k / domain.kt
Last active June 3, 2023 21:05
Effector - Kotlin - TodoList
val addClicked = Event.create<Unit>()
val textChanged = Event.create<String>()
val itemDeleted = Event.create<Int>()
private val itemAdded = Event.create<String>()
val storeText = Store.create("")
.on(textChanged) { _, newText -> newText }
.reset(itemAdded)
type WebPart = interface end
let reduceWebPart rules =
let emptyNodeParse _ n = failwithf "No resolver for: %O" n
let rec makeReducer (next: (WebPart -> _) -> WebPart -> _) (wp: WebPart) =
next (makeReducer next) wp
makeReducer (rules |> List.fold (fun a b -> b a) emptyNodeParse)
// ===============
@y2k
y2k / domain.clj
Created November 26, 2021 13:53
Events driven arch
(ns domain)
(listen-event
:item-created
(fn [e]
{:fetch {:url "https://backend.com/save"
:body {:text (:text e)}}}))
package kotlin.time
inline class Instant(val value: Duration) : Comparable<Instant> {
companion object {
val ZERO = Instant(Duration.ZERO)
fun fromUnixTimeSeconds(time: Long): Instant =
Instant(time.seconds)
class OpenClass { }
class FirstOpenClass : OpenClass { }
class SecondOpenClass : OpenClass { }
class Foo <TGen> where TGen : OpenClass, new() {
public TGen open = new TGen();
}
SecondOpenClass foo = new Foo<SecondOpenClass>().open;
open class OpenClass
class FirstOpenClass : OpenClass()
class SecondOpenClass : OpenClass()
class Foo<TGen : OpenClass>(
val open: TGen = FirstOpenClass() as TGen
) {
companion object {
fun build() = Foo(FirstOpenClass()) //it’s OK
}
static class ResultPair {
String response;
List<User> altered;
}
public Response subscriptionConfirmed(Message message, int addDays, String messageText, String userFilter) {
LocalDateTime now = LocalDateTime.now();
List<User> users = findUsers(message.getFrom(), userFilter);
ResultPair result = pureLogic(message, addDays, now, users);
@y2k
y2k / hackathon.fs
Created December 20, 2019 17:19
hackathon
open System
open FSharp.Data
type OnboardingType = XmlProvider<".data/onboarding.xml">
module Domain =
open SlackAPI
let toBlocks (cmd : OnboardingType.Command) : IBlock array =
cmd.Items
|> Seq.map ^ fun x ->
@y2k
y2k / scheme.txt
Created July 10, 2019 13:22
Fullstack Native Mobile Architecture
+----------------------------------------+ +----------------------------------------+
| | | |
| Mobile App Process | | Server Process |
| | | |
| +-----------+ +----------------+ | | +-------------+ +--------------------+ |
| | Android +---+ | | | | | | | | |
| | UIToolkin | | | V8 JS Engine | | Swagger | | Backend API | | Static JS bundle | |
| +-----------+ | | | | JSON | | | | | |
| | Android | | | Compiled to JS +----------------> | | from F#/Kotlin/... | |
| | Compose +-----+-+ * F# | | ProtoBuf | | +-------+-+---+ | |