I tested the library with a simple TodoMVC/Redux/ImmutableJS-like exercice here
Here is my redux-like reducer
fun todoReducer(store: Store, event: Event): Store {
val todos = when (event) {
DeleteCompleted -> store.todos.mutate { list->
list.removeIf(Todo::completed)
}
is AddTodo -> store.todos + Todo(event.id, event.text, false)
is RemoveTodo -> {
val todo = store.todo(event.id) ?: return store
store.todos - todo
}
is ToggleCompletedTodo -> {
val todo = store.todo(event.id) ?: return store
store.todos.mutate { list ->
list -= todo
list += todo.copy(completed = !todo.completed)
}
}
is EditTodo -> {
val todo = store.todo(event.id) ?: return store
store.todos.mutate { list ->
list -= todo
list += todo.copy(text = event.text)
}
}
}
return store.copy(todos = todos)
}
I tested the library with a simple TodoMVC/Redux/ImmutableJS-like exercice here
Here is my redux-like reducer
Had I use a
List
, I could have writtenDeleteCompleted -> store.todos.filterNot(Todo::completed)
But that won't work because there is no overload of
List.filter
DeleteCompleted -> store.todos.filterNot(Todo::completed).toImmutableList()
Not sure that this would be very efficient.
Without overloads of the
stdlib
extension functions,kotlinx.collections.immutable
feels IMHO like a step backward