Giter Site home page Giter Site logo

Comments (2)

Bogdanp avatar Bogdanp commented on June 20, 2024

Re. your first example, I would extract helper functions to help reduce the indentation:

#lang racket/gui/easy

(require racket/dict
         racket/function)

(struct food^ (name checked?) #:transparent)

(define (set-food^-checked? f checked?)
  (struct-copy food^ f [checked? checked?]))

(define (update-food foods k checked?)
  (dict-update foods k (curryr set-food^-checked? checked?)))

(define/obs @foods
  `((1 . ,(food^ "Apple" #t))
    (2 . ,(food^ "Banana" #f))
    (3 . ,(food^ "Broccoli" #f))
    (4 . ,(food^ "Ice Cream" #t))))
(obs-observe! @foods println)

(render
 (window
  #:size '(250 250)
  (list-view
   @foods
   #:key car
   (λ (k @id+food)
     (define @food (@id+food . ~> . cdr))
     (checkbox
      #:label (@food . ~> . food^-name)
      #:checked? (@food . ~> . food^-checked?)
      (λ (checked?)
        (@foods . <~ . (curryr update-food k checked?))))))))

Re. the match idea: I can't think of a way to write a match expander that produces derived observables, so I don't think that can work with regular match. I don't have any better ideas about how to further improve this code at the moment, either.

from racket-gui-easy.

cloudrac3r avatar cloudrac3r commented on June 20, 2024

Thanks for the reply! You're right, extracting those food operations to functions does make it easier to read and write the code. In the future, I might play around with making a limited version of list-view/match which just covers unpacking lists and structs, since those are the only data types I've found myself using in list-views.

from racket-gui-easy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.